0

我正在使用 IdentityServer4,我试图弄清楚如何在受保护的 API 中获取当前的 userId(guid)。前期是 BFF,它将所有请求代理到 API。当我查看 http 上下文时,没有可用的用户信息..并且User.isAuthenticated总是错误的。

我做了什么来获取该 API 中的一些用户数据?查询数据库的最小当前用户 UserId..

.AddAuthentication("token")  
 .AddJwtBearer("token", options =>
        {
            options.Authority = "https://localhost:6666";
            options.MapInboundClaims = false;

            options.TokenValidationParameters = new TokenValidationParameters()
            {
                ValidateAudience = true,
                ValidTypes = new[] { "at+jwt" },
                
                NameClaimType = "name",
                RoleClaimType = "role"
            };
        });

_contextAccessor.HttpContext.User.Identity.IsAuthenticated总是假的

4

0 回答 0