我有一个API,该API使用Identity Server 4进行基于JWT承载访问令牌的用户身份验证。
现在,当我在请求标头中传递access_token
时,我可以在控制器的用户对象中查看用户详细信息。
但是,如果我尝试访问DAL中的System.Security.Claims.ClaimsPrincipal
,则与登录用户不同。
这是我在Web Project Startup.cs中为Identity Server 4配置身份验证的方式
在ConfigureServices中-
services.AddAuthentication("Bearer").AddIdentityServerAuthentication(opt =>
{
opt.Authority = "http://auth......";
opt.RequireHttpsMetadata = true;
opt.ApiName = "API_NAME";
opt.NameClaimType = "username";
});
在“配置”中
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
#region Identity Server Config
// Setup Identity Server Options for this API -
app.UseAuthentication();
#endregion Identity Server Config
.....
}
如何在DAL中访问登录的Identity Server用户?