【发布时间】:2021-07-09 05:58:00
【问题描述】:
我正在使用 Azure AD 对用户进行授权和身份验证。 所有用户在数据库中都有一个配置文件。
我希望在登录时始终将 Azure 用户与我的数据库用户“合并”。
这是我用来在我的 web api 中设置身份验证的代码。
public static partial class ServiceCollectionExtensions
{
public static IServiceCollection AddBearerAuthentication(this IServiceCollection services,
OpenIdConnectOptions openIdConnectOptions)
{
#if DEBUG
IdentityModelEventSource.ShowPII = true;
#endif
services
.AddAuthentication("Bearer")
.AddJwtBearer("Bearer", o =>
{
o.Authority = openIdConnectOptions.Authority;
o.TokenValidationParameters.ValidIssuer = openIdConnectOptions.ValidIssuer;
o.TokenValidationParameters.ValidAudiences = openIdConnectOptions.ValidAudiences;
});
return services;
}
}
有人能指出我正确的方向吗? 现在我正在所有控制器中加载用户,一点也不漂亮。
【问题讨论】:
标签: asp.net-core identity iprincipal