身份服务器4和User.Claims.Properties.Count在客户端上始终为0

问题描述 投票:0回答:1

我需要在客户的索赔中填写“属性”。我在ProfileService类中记录了对IS4服务器的声明:

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

如何在客户端上获得索赔属性?

identityserver4
1个回答
0
投票

定义客户时,您也可以分配其所有权,这将包含在访问令牌中。

        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")
                }
            }
        };
© www.soinside.com 2019 - 2024. All rights reserved.