我们有一个 Asp.Net 4.5 MVC 应用程序,使用 Asp.Net Identity 来管理我们的客户数据库。我们目前正在使用 Microsoft 帐户身份验证。我们正在考虑使用 OpenId Connect,以便拥有工作/学校帐户的客户也可以登录 Add sign-in to an .NET MVC web app .
Microsoft 帐户身份验证返回 ProviderKey 作为已登录用户的唯一 ID。这映射到我们客户数据库中的 UserId。
OpenId Connect 似乎没有返回 ProviderKey,而是 NameIdentifier
看起来很有希望ClaimsPrincipal.Current.FindFirst(System.IdentityModel.Claims.ClaimTypes.NameIdentifier)?.Value;
是 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
映射自 NameId
或 Sub
来自 id_token 的声明(引用 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.
答案是肯定的,随着时间的推移,它可靠地用于唯一标识用户。
关于asp.net-identity - OpenId Connect 中用户的唯一 ID 是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43060736/