0

I am currently using library jwks-rsa. I want to extract the public key from identityServer4.

DecodedJWT jwt = JWT.decode(token);
try {
     URL url = new URL("https://localhost:31300/.well-known/openid-configuration/jwks");
     JwkProvider provider = new UrlJwkProvider(url);
     Jwk jwk = null;
     String kid = jwt.getKeyId();

     jwk = provider.get(kid);
     Algorithm algorithm = Algorithm.RSA256((RSAPublicKey) jwk.getPublicKey(), null);
     algorithm.verify(jwt);
     } catch (JwkException | MalformedURLException e) {
       e.printStackTrace();
  }

I am getting error at jwk=provider.get(kid). The exception is com.auth0.jwk.SigningKeyNotFoundException: Cannot obtain jwks from url https://localhost:31300/.well-known/openid-configuration/jwks However, I can access it through postman

{
    "keys": [
        {
            "kty": "RSA",
            "use": "sig",
            "kid": "0538f4763b647a8a01305774b9f4d5f1",
            "e": "AQAB",
            "n": "6h5hL5UfOW8SGFRNeVuU9M92p6cOWF-941vGqZ8y-PL6jC-B_2S7kp_Cw7SvOajd6CqBpQyiuP21pjhQILU4ikqq7-WbnxNZcvOQcYPLpUzupn5MBQkHk_bYONPInu-jU55FZhuYdO3sz0qS58AEqlnQbKZYLvU_KS_Ou4mSnTJr_hfwrk75cnsAMzhkVcsMt9GaSJZbj4zccIEUVQpiYLTY3gK_Nbym5ZKYfsayOHDSwLLsZchJ5VJnc1mAiZwGtszyjdCJSipQF_wdFcacmfGDwyXY4mnER32aT5Fo20lihnEJ5T1IXkwFMgWJVesiaHJQNqxAMEg86SWSN3_A0Q",
            "alg": "RS256"
        }
    ]
}
michael
  • 83
  • 1
  • 5

1 Answers1

0

The URL should be the url to IdentityServer, like this https://localhost:31300. Not the full path to the JWKS document itself.

Tore Nestenius
  • 16,431
  • 5
  • 30
  • 40