我无法访问数据访问层中的登录用户-身份服务器4和.NET 4.7.1

时间:2018-10-31 22:37:38

标签: .net asp.net-core identityserver4

我有一个API,该API使用Identity Server 4进行基于JWT承载访问令牌的用户身份验证。

现在,当我在请求标头中传递access_token时,我可以在控制器的用户对象中查看用户详细信息。

Controller User Property

但是,如果我尝试访问DAL中的System.Security.Claims.ClaimsPrincipal,则与登录用户不同。

DAL User Property

这是我在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用户?

0 个答案:

没有答案