Table of Contents
TokenValidator tokenValidator = TokenValidator.builder()
.issuerConfig(IssuerConfig.builder()
.issuerIdentifier("https://example.com")
.jwksContent(jwksJsonString)
.build())
.build();
try {
AccessTokenContent token = tokenValidator.createAccessToken(AccessTokenRequest.of(jwtString));
Optional<String> subject = token.getSubject();
List<String> roles = token.getRoles();
} catch (TokenValidationException e) {
LOGGER.error(e, "Token validation failed: %s", e.getMessage());
}AccessTokenCacheConfig cacheConfig = AccessTokenCacheConfig.builder()
.maxSize(1000)
.evictionIntervalSeconds(300L)
.build();
TokenValidator tokenValidator = TokenValidator.builder()
.cacheConfig(cacheConfig)
.issuerConfig(issuerConfig)
.build();
// Subsequent validations of the same token are served from cache
AccessTokenContent token1 = tokenValidator.createAccessToken(AccessTokenRequest.of(jwtString));
AccessTokenContent token2 = tokenValidator.createAccessToken(AccessTokenRequest.of(jwtString)); // From cacheTokenValidator tokenValidator = TokenValidator.builder()
.issuerConfig(IssuerConfig.builder()
.issuerIdentifier("https://keycloak.example.com/auth/realms/main")
.httpJwksLoaderConfig(HttpJwksLoaderConfig.builder()
.issuerIdentifier("https://keycloak.example.com/auth/realms/main")
.jwksUrl("https://keycloak.example.com/auth/realms/main/protocol/openid-connect/certs")
.build())
.build())
.issuerConfig(IssuerConfig.builder()
.issuerIdentifier("https://auth0.example.com/")
.httpJwksLoaderConfig(HttpJwksLoaderConfig.builder()
.issuerIdentifier("https://auth0.example.com/")
.jwksUrl("https://auth0.example.com/.well-known/jwks.json")
.build())
.build())
.build();
// Validator automatically selects correct issuer based on token
AccessTokenContent token = tokenValidator.createAccessToken(AccessTokenRequest.of(jwtString));IssuerConfig issuerConfig = IssuerConfig.builder()
.httpJwksLoaderConfig(HttpJwksLoaderConfig.builder()
.wellKnownUrl("https://accounts.google.com/.well-known/openid-configuration")
.build())
.expectedAudience("your-google-client-id")
.build();IssuerConfig issuerConfig = IssuerConfig.builder()
.issuerIdentifier("https://example.com")
.jwksContent(jwksJsonString)
.claimMapper("roles", customRolesMapper) // Custom mapper for nested roles
.claimMapper("groups", customGroupsMapper) // Custom mapper for groups
.build();
TokenValidator validator = TokenValidator.builder()
.issuerConfig(issuerConfig)
.build();
AccessTokenContent token = validator.createAccessToken(AccessTokenRequest.of(jwtString));
List<String> roles = token.getRoles(); // From custom roles mapper
List<String> groups = token.getGroups(); // From custom groups mapperFor more examples, see the API Reference.