ProviderDiscoveryClient { public ProviderConfiguration discover() { Map responseAttributes = this.restTemplate.getForObject(this.providerLocation, Map.class); ProviderConfiguration.Builder builder = new ProviderConfiguration.Builder(); builder.issuer((String)responseAttributes.get(ISSUER_ATTR_NAME)); builder.authorizationEndpoint((String)responseAttributes.get(AUTHORIZATION_ENDPOINT_ATTR_NAME)); if (responseAttributes.containsKey(TOKEN_ENDPOINT_ATTR_NAME)) { builder.tokenEndpoint((String)responseAttributes.get(TOKEN_ENDPOINT_ATTR_NAME)); } if (responseAttributes.containsKey(USERINFO_ENDPOINT_ATTR_NAME)) { builder.userInfoEndpoint((String)responseAttributes.get(USERINFO_ENDPOINT_ATTR_NAME)); } if (responseAttributes.containsKey(JWK_SET_URI_ATTR_NAME)) { builder.jwkSetUri((String)responseAttributes.get(JWK_SET_URI_ATTR_NAME)); } return builder.build(); } ProviderDiscoveryClient(String providerLocationUri); ProviderConfiguration discover();  }
@Test public void discoverWhenProviderSupportsDiscoveryThenReturnProviderConfiguration() throws Exception { this.server.enqueue(new MockResponse().setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE).setBody( " {\n" + " \"issuer\": \"https: " \"authorization_endpoint\": \"https: " \"token_endpoint\": \"https: " \"userinfo_endpoint\": \"https: " \"jwks_uri\": \"https: " }\n")); ProviderDiscoveryClient client = new ProviderDiscoveryClient(this.server.url("").toString()); ProviderConfiguration providerConfiguration = client.discover(); assertNotNull(providerConfiguration); assertEquals("https: assertEquals("https: assertEquals("https: assertEquals("https: assertEquals("https: }
@Test(expected = RestClientException.class) public void discoverWhenProviderDoesNotSupportDiscoveryThenThrowRestClientException() throws Exception { this.server.enqueue(new MockResponse().setResponseCode(404)); ProviderDiscoveryClient client = new ProviderDiscoveryClient(this.server.url("").toString()); client.discover(); }