Sebastian Busek
Sebastian Busek

Reputation: 1032

set claim value as array in IdentityServer3

We're using IdentityServer3 as Identity provider and one of our claims are Permissions.

But when user has only one permissions, resulting JWT contains property with name "permission" but value is simple string otherwise it's an array. How can we declare claim value "permission" as an array?

Here is snipper how we're filling claims:

foreach (var permission in permissions)
{
    claims.Add(new Claim(Scopes.SCOPE_PERMISSION, $"{permission.id}>>{permission.name}"));
}

Upvotes: 1

Views: 1428

Answers (1)

Sebastian Busek
Sebastian Busek

Reputation: 1032

Identity server comes with value type json, so "permission" property can be encapsulated as

claims.Add(
    new Claim(
        Scopes.SCOPE_PERMISSION,
        JsonConvert.SerializeObject(permissions.Select(s => $"{s.id}>>{s.name}")),
        "json"));

Upvotes: 2

Related Questions