Skip to content

Commit

Permalink
Force key retrieval
Browse files Browse the repository at this point in the history
  • Loading branch information
bstewartlg committed May 3, 2024
1 parent d5fa9b6 commit bd0291c
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,12 @@ private boolean validateToken(String authHeader) throws NoSuchAlgorithmException
throw new JWTVerificationException("Invalid issuer: Expected \"" + issuer + "\" but received \"" + decodedJWT.getIssuer() + "\"");
}

// TODO: implement caching
// check if we already have the public key
if (rsaPublicKey == null) {
// if (rsaPublicKey == null) {

// check if the public key was supplied in the configuration and attempt to use it
// _logger.info("!StringUtils.isEmpty(publicKey): " + !StringUtils.isEmpty(publicKey));
if (!StringUtils.isEmpty(publicKey)) {
byte[] publicBytes = Base64.decodeBase64(publicKey);
X509EncodedKeySpec keySpec = new X509EncodedKeySpec(publicBytes);
Expand All @@ -191,6 +193,7 @@ private boolean validateToken(String authHeader) throws NoSuchAlgorithmException
String jwksUri = new ObjectMapper().readTree(response.body()).get("jwks_uri").asText();

JwkProvider provider = new UrlJwkProvider(new URL(jwksUri));
// _logger.info("decodedJWT.getKeyId(): " + decodedJWT.getKeyId());
Jwk jwk = provider.get(decodedJWT.getKeyId());

rsaPublicKey = (RSAPublicKey) jwk.getPublicKey();
Expand All @@ -201,7 +204,7 @@ private boolean validateToken(String authHeader) throws NoSuchAlgorithmException
throw new JWTVerificationException("Could not determine public key");
}

}
// }


Algorithm algorithm = Algorithm.RSA256(rsaPublicKey, null);
Expand Down

0 comments on commit bd0291c

Please sign in to comment.