Create a JsonWebKey from JSON

2k views Asked by At

I have a url that has my jwks values. It looks like this

{
  "keys": [
   {
       "kty": "RSA",
       "e": "AQAB",
       "use": "sig",
       "kid": "Has a Real Value Here",
       "alg": "RS256",
       "n": "Has a Real Value here"
   }]
}

I tried to take that json, and feed it into the JsonWebKey constructor like this:

HttpClient client = new HttpClient();
var response = client.GetAsync("https://myIdp/oauth2/jwks").Result;
var jwksString = response.Content.ReadAsStringAsync().Result;

publicJwk = new JsonWebKey(jwksString);

When I do that, none of the values in the class get populated. The thing that gets a value is a AdditionalData field. It gets all to the json put there.

Is there a way to get the JsonWebKey constructor to actually parse out the Json?

1

There are 1 answers

0
Dinesh On

the jwks values are array so you need to you jsonwebkeyset which is an collection of jsonwebkey. something like this:

HttpClient client = new HttpClient();
var response = client.GetAsync("https://myIdp/oauth2/jwks").Result;
var jwksString = response.Content.ReadAsStringAsync().Result;

jwkset = new JsonWebKeySet(jwksString);