从OAuth令牌Asp.net MVC获取电子邮件地址

时间:2018-03-05 05:28:12

标签: asp.net-mvc token owin claims-based-identity

我在import { Component, OnInit, OnDestroy } from '@angular/core'; import { ActivatedRoute, Route, Router } from '@angular/router'; import { ListComponent } from '../list/list.component'; @Component({ selector: 'app-detail', templateUrl: './detail.component.html', styleUrls: ['./detail.component.css'] }) export class DetailComponent implements OnInit, OnDestroy { contact_id: string; private sub: any; numd = 1; constructor( private _activatedRoute: ActivatedRoute, private _router: Router) { console.log('创建DeatilComponent组件实例'); } ngOnInit() { this.sub = this._activatedRoute.params.subscribe(params => { this.contact_id = params['id']; console.log('参数id为:' + this.contact_id); }); } nextInfo() { console.log(this.numd); // this.numd++; } ngOnDestroy() { this.sub.unsubscribe(); } } Web API中使用OAuth安全性。我在Asp.net MVC中添加了一个电子邮件地址和密码来生成令牌。它按预期正常工作。

现在,为了获取用户数据,我想将令牌转换为电子邮件地址并根据它获取数据。有可能吗?

1 个答案:

答案 0 :(得分:1)

您可以在行动中使用此代码

public class TestController : ApiController
{
    public void Test()
    {
        string email = ((ClaimsIdentity)User.Identity).FindFirst(<EMAIL_CLAIM_TYPE>).Value;
    }
}