Пользовательские утверждения не доступны на клиенте с identityserver 4 .Net core 2.0 - PullRequest
0 голосов
/ 29 мая 2018

В моем клиенте 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
            });

Ниже приводится файл startup.cs моего Identityserver

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);
        }
    }

Я не могу получить доступ к претензии Mail в клиентском приложении.

Проверено много ссылок.

Но никто из них не работает для меня.Любое предположение, что может отсутствовать?

Использование Identityserver4 с ядром .Net 2.

Ответы [ 2 ]

0 голосов
/ 30 мая 2018

Неважно.Я получил это, решив следующую опцию в конфигурации клиента сервера.Прочитайте это полностью.Но пока он работает так, как будто он включает в себя утверждения в токене.

AlwaysIncludeUserClaimsInIdToken = true
0 голосов
/ 30 мая 2018

Области по умолчанию для OpenIDConnectOptions - "openid" и "profile".

При настройке параметров вам потребуется дополнительно запросить область "email".

...