In version 3.1.1 I was able to create JWTs using the following object structure (see below) but in the latest release (both 3.2.0 and 4.0.0) this is failing. I get a JWT back but when I validate this at either jwt.io or jwt.ms the scopes array is empty (using latest version) however downgrade the package to 3.1.1 it works fine.
This is the expected output:
{
"client_id": "faee211841724a53bd5775b6ce8b38b8",
"scope": [
"hello",
"world",
"foo",
"bar",
"john",
"doe"
],
"iat": 637879035209350400,
"aud": "foobar",
"auth_time": 637879035209350400,
"iss": "http://foobar",
"exp": 637879071209353000,
"nbf": 637879034609354100
}
However with anything above 3.1.1 I get:
{
"client_id": "faee211841724a53bd5775b6ce8b38b8",
"scope": [
[],
[],
[],
[],
[],
[]
],
"iat": 637879035209350400,
"aud": "foobar",
"auth_time": 637879035209350400,
"iss": "http://foobar",
"exp": 637879071209353000,
"nbf": 637879034609354100
}
Reproduce by copying and pasting this code:
using System.Text.Json.Serialization;
using Jose;
using Newtonsoft.Json;
string[] defaultScopes = {
"hello",
"world",
"foo",
"bar",
"john",
"doe"
};
var token = new TokenDetails
{
ClientId = Guid.NewGuid().ToString("N"),
ClientScopes = defaultScopes
};
var claims = JsonConvert.DeserializeObject<Dictionary<string, object>>(System.Text.Json.JsonSerializer.Serialize(token));
var utcNow = DateTime.UtcNow.Ticks;
claims["iat"] = utcNow;
claims["aud"] = "foobar";
claims["auth_time"] = utcNow;
claims["iss"] = "http://foobar";
claims["exp"] = DateTime.UtcNow.AddHours(1).Ticks;
claims["nbf"] = DateTime.UtcNow.AddMinutes(-1).Ticks;
var secretKey = new byte[]{164,60,194,0,161,189,41,38,130,89,141,164,45,170,159,209,69,137,243,216,191,131,47,250,32,107,231,117,37,158,225,234};
var tokenString = JWT.Encode(claims /* */, secretKey, JwsAlgorithm.HS256);
Console.Write(tokenString);
Console.Read();
public class TokenDetails
{
[JsonPropertyName("client_id")]
public string ClientId { get; set; }
[JsonPropertyName("scope")]
public string[] ClientScopes { get; set; }
}
Am I doing something wrong here? Something has changed but perhaps I need to do something different..
In version 3.1.1 I was able to create JWTs using the following object structure (see below) but in the latest release (both 3.2.0 and 4.0.0) this is failing. I get a JWT back but when I validate this at either jwt.io or jwt.ms the
scopesarray is empty (using latest version) however downgrade the package to 3.1.1 it works fine.This is the expected output:
However with anything above 3.1.1 I get:
Reproduce by copying and pasting this code:
Am I doing something wrong here? Something has changed but perhaps I need to do something different..