Identity Server 4 и User.Claims.Properties.Count всегда равен 0 на клиенте - PullRequest
0 голосов
/ 24 марта 2020

Мне нужно заполнить «Свойства» в претензии клиента. Я записываю претензию на сервер IS4 в классе ProfileService:

public async Task GetProfileDataAsync(ProfileDataRequestContext context)
 {
 // ...
 Claim claim = new Claim("userData", "personalRights");
    string valuePersonalRights = JsonConvert.SerializeObject(userRights);
    claim.Properties.Add(GetKeyValuePair("rights", valuePersonalRights));
    claims.Add(claim);

 context.IssuedClaims.AddRange(claims);
 }

private KeyValuePair<string, string> GetKeyValuePair(string key, string value)
{
   KeyValuePair<string, string> keyValuePair = new KeyValuePair<string, string>(key, value);

   return keyValuePair;
}

В этой претензии на сервере есть записи "Свойства": https://postgres-russia.ru/wp-content/files/is4_img/on_server.jpg

Однако на клиенте свойства этой заявки отсутствуют: https://postgres-russia.ru/wp-content/files/is4_img/on_client.jpg

Конфигурация клиента:

 services.AddAuthentication(options =>
                {
                    options.DefaultScheme = "Cookies";
                    options.DefaultChallengeScheme = "oidc";
                })
                .AddCookie("Cookies")
                .AddOpenIdConnect("oidc", options =>
                {
                    options.Authority = "http://localhost:5000";
                    options.RequireHttpsMetadata = false;
                    options.ClientId = "mvc";
                    options.ClientSecret = "secret";
                    options.ResponseType = "code";
                    options.Scope.Add("openid");
                    options.Scope.Add("profile");
                    options.Scope.Add("email");
                    options.Scope.Add("domainGroups");
                    options.Scope.Add("geolocation");
                    options.Scope.Add("fullname");
                    options.SaveTokens = true;
                    options.TokenValidationParameters = new TokenValidationParameters
                    {
                        NameClaimType = "name"
                    };
                });

Как получить свойства заявок на клиенте

1 Ответ

0 голосов
/ 26 марта 2020

Когда вы определяете своего клиента, вы также можете назначить его претензии, которые будут включены в токен доступа.

        public static IEnumerable<Client> Clients =>
        new Client[]
        {
            new Client
            {
                ClientId = "spa",
                ClientName = "SPA Client",
                ClientUri = "",
                AllowedGrantTypes = {GrantType.ResourceOwnerPassword,GrantType.ClientCredentials},
                RedirectUris =
                {
                },
                RequireClientSecret = false,
                // secret for authentication
                ClientSecrets =
                {
                    new Secret("secret".Sha256())
                },
                PostLogoutRedirectUris = { "" },
                AllowedCorsOrigins = { "","" },
                AllowedScopes = { "openid", "profile","roles", IdentityServerConstants.LocalApi.ScopeName },
                Claims = new Claim[]//look at this property
                {
                    new Claim("prop1","value1")
                }
            }
        };
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...