加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-identity – OpenId Connect中用户的唯一ID

发布时间:2020-12-16 06:50:41 所属栏目:asp.Net 来源:网络整理
导读:我们有一个使用Asp.Net Identity的Asp.Net 4.5 MVC应用程序来管理我们的客户数据库.我们目前正在使用Microsoft帐户身份验证.我们正在考虑使用OpenId Connect,以便拥有工作/学校帐户的客户也可以登录 Add sign-in to an .NET MVC web app. Microsoft Account
我们有一个使用Asp.Net Identity的Asp.Net 4.5 MVC应用程序来管理我们的客户数据库.我们目前正在使用Microsoft帐户身份验证.我们正在考虑使用OpenId Connect,以便拥有工作/学校帐户的客户也可以登录 Add sign-in to an .NET MVC web app.

Microsoft Account Authentication返回ProviderKey作为已登录用户的唯一ID.这将映射到我们的客户数据库中的UserId.

OpenId Connect似乎没有返回ProviderKey,但NameIdentifier看起来很有希望
ClaimsPrincipal.Current.FindFirst(System.IdentityModel.Claims.ClaimTypes.NameIdentifier)?.值;

NameIdentifier是OpenId Connect返回的用户的唯一标识符吗?是否可以可靠地用于随着时间的推移唯一地识别用户?

解决方法

Is NameIdentifier the unique identifier of the user returned by OpenId Connect? Can it be reliably used to uniquely identify a user over time?

AFAIK,NameIdentifier是从idIt中的NameId或Sub声明映射的(参见here).对于Azure AD的id_token,它使用了Sub声明.

并且从sub claim的描述:

Identifies the principal about which the token asserts information,such as the user of an application. This value is immutable and cannot be reassigned or reused,so it can be used to perform authorization checks safely. Because the subject is always present in the tokens the Azure AD issues,we recommended using this value in a general purpose authorization system.

答案是肯定的,它可靠地用于随着时间的推移唯一地识别用户.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读