【问题标题】:Custom Claims are not being accessed in client with identityserver 4 .Net core 2.0使用 identityserver 4 .Net core 2.0 在客户端中未访问自定义声明
【发布时间】:2018-11-08 12:32:03
【问题描述】:

我的客户端 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 结合使用。

【问题讨论】:

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


    【解决方案1】:

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

    AlwaysIncludeUserClaimsInIdToken = true
    

    【讨论】:

    • 谢谢!,浪费了一整天的时间在网上做所有其他建议,只是发现这条线解决了问题。
    【解决方案2】:

    The default scopes for OpenIDConnectOptions are "openid" and "profile".

    在配置选项时,您必须另外请求“电子邮件”范围。

    【讨论】:

    • 还是没来。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-27
    • 2020-07-24
    • 2022-01-01
    相关资源
    最近更新 更多