com.auth0.jwk.UrlJwkProvider Java Examples
The following examples show how to use
com.auth0.jwk.UrlJwkProvider.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CachingOpenIdMetadata.java From botbuilder-java with MIT License | 7 votes |
private void refreshCache() { keyCache.clear(); try { URL openIdUrl = new URL(this.url); HashMap<String, String> openIdConf = this.mapper.readValue(openIdUrl, new TypeReference<HashMap<String, Object>>() { }); URL keysUrl = new URL(openIdConf.get("jwks_uri")); lastUpdated = System.currentTimeMillis(); UrlJwkProvider provider = new UrlJwkProvider(keysUrl); keyCache = provider.getAll().stream().collect(Collectors.toMap(Jwk::getId, jwk -> jwk)); } catch (IOException e) { LOGGER.error(String.format("Failed to load openID config: %s", e.getMessage())); lastUpdated = 0; } catch (SigningKeyNotFoundException keyexception) { LOGGER.error("refreshCache", keyexception); lastUpdated = 0; } }
Example #2
Source File: JWTVerifierFactory.java From spring-jwt-gateway with Apache License 2.0 | 6 votes |
@Bean @Qualifier("jwk") public JWTVerifier create(@Value("${jwt.issuer}") String issuer, @Value("${jwt.audience}") String audience) throws JwkException, IOException { UrlJwkProvider urlJwkProvider = new UrlJwkProvider(issuer); RestTemplate restTemplate = new RestTemplate(); ObjectMapper objectMapper = new ObjectMapper(); JsonNode jsonNode = objectMapper.readTree(restTemplate.getForObject(issuer + "/.well-known/jwks.json", String.class)); String kid = jsonNode.get("keys").get(0).get("kid").asText(); Jwk jwk = urlJwkProvider.get(kid); return JWT.require(Algorithm.RSA256((RSAPublicKey) jwk.getPublicKey(), null)) .withIssuer(issuer) .withAudience(audience) .build(); }
Example #3
Source File: KeycloakJwkProvider.java From che with Eclipse Public License 2.0 | 5 votes |
@Inject public KeycloakJwkProvider(KeycloakSettings keycloakSettings) throws MalformedURLException { final String jwksUrl = keycloakSettings.get().get(KeycloakConstants.JWKS_ENDPOINT_SETTING); if (jwksUrl == null) { throw new ConfigurationException("Jwks endpoint url not found in keycloak settings"); } this.jwkProvider = new GuavaCachedJwkProvider(new UrlJwkProvider(new URL(jwksUrl))); }