Add a claim to JWT as an array?

后端 未结 4 1046
醉话见心
醉话见心 2021-01-01 17:52

Using thinktecture JWT authentication resource owner flow,i use the claims part of JWT for client consumption. My question is that if its possible to add claim in identity s

4条回答
  •  死守一世寂寞
    2021-01-01 18:35

    Identity Server will convert the value from an array to string if you want to add a single value to an array. An easier solution would be to convert the array as json and add to the claim with valueType as json.

    IList companies = new List();
    companies.Add("CompanyA");
    string companiesJson = JsonConvert.SerializeObject(companies);
    context.IssuedClaims.Add(new Claim("Companies", companiesJson, IdentityServerConstants.ClaimValueTypes.Json));
    

    The above solution will allow you to add one or more values to claim as an array.

提交回复
热议问题