0

Using dotnet user-jwts tool, I'm trying to generate a token that would have a custom claim that is an array of values, and not a name/value pair. When decoded, this token should look something like this:

{
    "unique_name": "User",
    "sub": "User",
    "jti": "jwtid",
    "groups": [
        "group1",
        "group2"
    ],
    "aud": "http://localhost:5000",
    "nbf": 1600000000,
    "exp": 1700000000,
    "iat": 1600000000,
    "iss": "dotnet-user-jwts"
}

However, I can't seem to create "groups" claim in this format.

What I've tried so far:

First approach:

dotnet user-jwts create --claim 'groups=[ "group1", "group2" ]'

Generates error:

'n' is invalid after a single JSON value. Expected end of data. Path: $ | LineNumber: 22 | BytePositionInLine: 1.

Generated decoded token is similar to this one:

{
    "unique_name": "User",
    "sub": "User",
    "jti": "jwtid",
    "groups": "[group1,group2]",
    "aud": "http://localhost:5000",
    "nbf": 1600000000,
    "exp": 1700000000,
    "iat": 1600000000,
    "iss": "dotnet-user-jwts"
}

Switching " and ' provides similar result, which is still a string.

Second approach:

dotnet user-jwts create --claim "groups=group1" --claim "groups=group2"

Generates this error:

An item with the same key has already been added. Key: groups

And nothing is generated.

How should I go around creating a custom claim that would be an array of string values, and not a string?

Meskenas
  • 1
  • 1

0 Answers0