I can't access my logged in user in my Data Access Layer - Identity server 4 and .NET 4.7.1

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-05 05:30:43

问题


I have an API that uses Identity Server 4 for User Authentication based on JWT Bearer Access Token.

Now when I Pass in the access_token in my request header I can view the User Details in the User Object in the Controller.

But if I try to access the System.Security.Claims.ClaimsPrincipal in my DAL it is different to my logged in user.

This is how I configured Authentication for Identity Server 4 in my Web Project Startup.cs

In ConfigureServices -

services.AddAuthentication("Bearer").AddIdentityServerAuthentication(opt =>
        {
            opt.Authority = "http://auth......";
            opt.RequireHttpsMetadata = true;
            opt.ApiName = "API_NAME";
            opt.NameClaimType = "username";
        });

In Configure

    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        #region Identity Server Config

        // Setup Identity Server Options for this API -
        app.UseAuthentication();

        #endregion Identity Server Config
        .....
    }

How do I access my logged in Identity Server user in the DAL?

来源:https://stackoverflow.com/questions/53092899/i-cant-access-my-logged-in-user-in-my-data-access-layer-identity-server-4-and

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!