.net-core - 在使用身份服务器 4 .Net core 2.0 的客户端中未访问自定义声明

标签 .net-core asp.net-core-mvc asp.net-core-2.0 identityserver4

我在我的客户端 startup.cs 中有以下内容。

services.AddAuthentication(options =>
            {
                options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
                options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
            })
            .AddCookie()
            .AddOpenIdConnect(options =>
            {
                options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme; // cookie middle setup above
                options.Authority = AuthSetting["Authority"];  // Auth Server
                options.RequireHttpsMetadata = false; // only for development 
                options.ClientId = AuthSetting["ClientId"]; // client setup in Auth Server
                options.ClientSecret = AuthSetting["ClientSecret"];
                options.ResponseType = "code id_token"; // means Hybrid flow (id + access token)
                options.GetClaimsFromUserInfoEndpoint = true;
                options.SaveTokens = true;
                //options.ClaimActions.MapJsonKey(ClaimTypes.Email, "email", ClaimValueTypes.Email);
                //options.ClaimActions.Clear(); //https://stackoverflow.com/a/47896180/9263418
                //options.ClaimActions.MapUniqueJsonKey("Aes", "Aes");
                //options.ClaimActions.MapUniqueJsonKey("foo", "foo");
                //options.ClaimActions.MapJsonKey("Aes", "Aes"); //https://github.com/aspnet-contrib/AspNet.Security.OAuth.Providers/issues/210
            });

以下是我的 Identityserver 的 startup.cs
services.AddIdentityServer(options =>
                {
                    options.Events.RaiseSuccessEvents = true;
                    options.Events.RaiseFailureEvents = true;
                    options.Events.RaiseErrorEvents = true;
                    options.Events.RaiseInformationEvents = true;
                })
                .AddInMemoryClients(Clients.Get())
                .AddInMemoryIdentityResources(Resources.GetIdentityResources())
                .AddInMemoryApiResources(Resources.GetApiResources())
                .AddDeveloperSigningCredential()
                .AddExtensionGrantValidator<Extensions.ExtensionGrantValidator>()
                .AddExtensionGrantValidator<Extensions.NoSubjectExtensionGrantValidator>()
                .AddJwtBearerClientAuthentication()
                .AddAppAuthRedirectUriValidator()
                .AddClientConfigurationValidator<DefaultClientConfigurationValidator>()
                .AddProfileService<ProfileService>();

以下是我的 ProfileService.cs 文件。
public class ProfileService : IProfileService
    {

        public Task GetProfileDataAsync(ProfileDataRequestContext context)
        {
            // Processing
            var claims = new List<Claim>
            {
                new Claim("Email", "someone2gmail.com"),
            };

            context.IssuedClaims.AddRange(claims);

            return Task.FromResult(0);
        }

        public Task IsActiveAsync(IsActiveContext context)
        {
            // Processing
            context.IsActive = true;

            return Task.FromResult(0);
        }
    }

我无法在客户端应用程序中访问邮件声明。

查了很多引用资料。

但他们都没有为我工作。任何猜测可能会丢失什么?

将 Identityserver4 与 .Net core 2 一起使用。

最佳答案

没关系。我通过在服务器的客户端配置中尝试以下选项来解决它。将完整阅读。但就目前而言,它的工作原理似乎是在 token 中包含声明。

AlwaysIncludeUserClaimsInIdToken = true

关于.net-core - 在使用身份服务器 4 .Net core 2.0 的客户端中未访问自定义声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50591356/

相关文章:

asp.net - 生成 ModelState 字典的键

dotnet 核心 2.0 中的 XML 差异比较

c# - 找不到 Microsoft.AspNetCore.Antiforgery

c# - Asp.net Core 2 - 如何在 Asp.net Core 2.0 中使用 ServiceLocator

.net-core - 使用 RabbitMQ 发布/订阅微服务事件总线时如何去重事件

c# - Selenium 与 .net core : performance impact, IWebElement 中的多个线程?

asp.net-core-mvc - 错误请求 - 从 LAN 访问本地主机 Web API 或 Web 应用程序时主机名无效

automapper - 如何正确使用 EF Core 和 AutoMapper ProjectTo 和 Unions?

angular - 如何对 dotnet 核心 Angular 模板应用程序进行 docker 化?

asp.net - 使用 AddMvcCore 配置 JsonOutputFormatter