【发布时间】:2019-09-24 16:56:41
【问题描述】:
我正在制作一个报告系统,允许用户使用 Azure 凭据登录,然后他们将订阅/取消订阅报告。
它目前使用的 ASP.NET Identity 运行良好,但需要更多 IT 支持,因为人们忘记了他们的凭据等。
如何将 Azure 凭据保存到 ASP.NET Identity 中?就像它与 Facebook 等其他外部提供商一样,或者您是否会避免一起使用 ASP.NET Identity 并将电子邮件地址保存到表中并引用该表而不是 ASP.NET Identity 版本?
Startup.cs
services.AddAuthentication(AzureADDefaults.AuthenticationScheme)
.AddAzureAD(options => Configuration.Bind("AzureAd", options));
services.Configure<OpenIdConnectOptions>(AzureADDefaults.OpenIdScheme, options =>
{
options.Authority = options.Authority + "/v2.0/";
// Per the code below, this application signs in users in any Work and School
// accounts and any Microsoft Personal Accounts.
// If you want to direct Azure AD to restrict the users that can sign-in, change
// the tenant value of the appsettings.json file in the following way:
// - only Work and School accounts => 'organizations'
// - only Microsoft Personal accounts => 'consumers'
// - Work and School and Personal accounts => 'common'
// If you want to restrict the users that can sign-in to only one tenant
// set the tenant value in the appsettings.json file to the tenant ID of this
// organization, and set ValidateIssuer below to true.
// If you want to restrict the users that can sign-in to several organizations
// Set the tenant value in the appsettings.json file to 'organizations', set
// ValidateIssuer, above to 'true', and add the issuers you want to accept to the
// options.TokenValidationParameters.ValidIssuers collection
options.TokenValidationParameters.ValidateIssuer = false;
// Custom
options.Scope.Add("email");
//options.Scope.Add("profile");
options.SaveTokens = true;
options.GetClaimsFromUserInfoEndpoint = true;
options.TokenValidationParameters = new TokenValidationParameters
{
NameClaimType = "name"
};
});
感谢阅读。
编辑: 现在,我只是使用 TokenValidated 事件,然后使用带有 CreateAsync 的 UserManager 创建用户。
【问题讨论】:
标签: asp.net-core azure-active-directory asp.net-identity