asp.net-identity - OpenId Connect 中用户的唯一 ID 是什么

标签 asp.net-identity azure-active-directory openid-connect adal msal

我们有一个 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映射自 NameIdSub来自 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/

相关文章:

asp.net-mvc - 适用于多个项目的单一 ASP.NET 身份

asp.net-core - 使用 EF Core IdentityContext 和 DbContext 进行订单管理

c# - 无法通过C# Graph API向AD添加用户——为什么调用GraphServiceClient.Users.PostAsync()时出现 "OData Error"?

azure - 保护 Azure 函数的安全

c# - Active Directory redirect_uri 显示 IP 而不是 DNS 名称。如何在使用 Azure AD 进行身份验证时在代码中提供绝对 CallbackPath?

asp.net-mvc - IdentityServer 4、OpenIdConnect 重定向到外部登录 url

asp.net - 为什么 ASP.Net Identity 不支持删除

c# - 存储和检索在使用 facebook 或 twitter 授权后为用户收到的 token

postgresql - 如何使用用户名和密码从 Azure AD 检索到的 token 对 Azure PostgreSQL 进行身份验证?

single-sign-on - 同一域中的 OpenID Connect RP 和 OP?