Skip to content

Commit

Permalink
Merge pull request #600 from auth0/readme-update-jwk-usage
Browse files Browse the repository at this point in the history
Provide straightforward example for JWKS
  • Loading branch information
poovamraj authored Jul 26, 2022
2 parents f799e58 + 81c8b46 commit 298b954
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,18 +199,18 @@ By using a `KeyProvider` you can change in runtime the key used either to verify
- `getPrivateKeyId()`: Its called during token signing and it should return the id of the key that identifies the one returned by `getPrivateKey()`. This value is preferred over the one set in the `JWTCreator.Builder#withKeyId(String)` method. If you don't need to set a `kid` value avoid instantiating an Algorithm using a `KeyProvider`.


The following example shows how this would work with `JwkStore`, an imaginary [JWK Set](https://auth0.com/docs/jwks) implementation. For simple key rotation using JWKS, try the [jwks-rsa-java](https://github.com/auth0/jwks-rsa-java) library.
The following example shows how this would work with `JwkProvider` from the [jwks-rsa-java](https://github.com/auth0/jwks-rsa-java) library.

```java
final JwkStore jwkStore = new JwkStore("{JWKS_FILE_HOST}");
final JwkProvider jwkProvider = new UrlJwkProvider("https://samples.auth0.com/");
final RSAPrivateKey privateKey = //Get the key instance
final String privateKeyId = //Create an Id for the above key

RSAKeyProvider keyProvider = new RSAKeyProvider() {
@Override
public RSAPublicKey getPublicKeyById(String kid) {
//Received 'kid' value might be null if it wasn't defined in the Token's header
RSAPublicKey publicKey = jwkStore.get(kid);
PublicKey publicKey = jwkProvider.get(kid).getPublicKey();
return (RSAPublicKey) publicKey;
}

Expand Down

0 comments on commit 298b954

Please sign in to comment.