use of org.springframework.security.oauth2.client.registration.ClientRegistration.ProviderDetails in project spring-security by spring-projects.
the class CommonOAuth2ProviderTests method getBuilderWhenFacebookShouldHaveFacebookSettings.
@Test
public void getBuilderWhenFacebookShouldHaveFacebookSettings() {
ClientRegistration registration = build(CommonOAuth2Provider.FACEBOOK);
ProviderDetails providerDetails = registration.getProviderDetails();
assertThat(providerDetails.getAuthorizationUri()).isEqualTo("https://www.facebook.com/v2.8/dialog/oauth");
assertThat(providerDetails.getTokenUri()).isEqualTo("https://graph.facebook.com/v2.8/oauth/access_token");
assertThat(providerDetails.getUserInfoEndpoint().getUri()).isEqualTo("https://graph.facebook.com/me?fields=id,name,email");
assertThat(providerDetails.getUserInfoEndpoint().getUserNameAttributeName()).isEqualTo("id");
assertThat(providerDetails.getJwkSetUri()).isNull();
assertThat(registration.getClientAuthenticationMethod()).isEqualTo(ClientAuthenticationMethod.CLIENT_SECRET_POST);
assertThat(registration.getAuthorizationGrantType()).isEqualTo(AuthorizationGrantType.AUTHORIZATION_CODE);
assertThat(registration.getRedirectUri()).isEqualTo(DEFAULT_REDIRECT_URL);
assertThat(registration.getScopes()).containsOnly("public_profile", "email");
assertThat(registration.getClientName()).isEqualTo("Facebook");
assertThat(registration.getRegistrationId()).isEqualTo("123");
}
use of org.springframework.security.oauth2.client.registration.ClientRegistration.ProviderDetails in project spring-security by spring-projects.
the class CommonOAuth2ProviderTests method getBuilderWhenOktaShouldHaveOktaSettings.
@Test
public void getBuilderWhenOktaShouldHaveOktaSettings() {
ClientRegistration registration = builder(CommonOAuth2Provider.OKTA).authorizationUri("https://example.com/auth").tokenUri("https://example.com/token").userInfoUri("https://example.com/info").jwkSetUri("https://example.com/jwkset").build();
ProviderDetails providerDetails = registration.getProviderDetails();
assertThat(providerDetails.getAuthorizationUri()).isEqualTo("https://example.com/auth");
assertThat(providerDetails.getTokenUri()).isEqualTo("https://example.com/token");
assertThat(providerDetails.getUserInfoEndpoint().getUri()).isEqualTo("https://example.com/info");
assertThat(providerDetails.getUserInfoEndpoint().getUserNameAttributeName()).isEqualTo(IdTokenClaimNames.SUB);
assertThat(providerDetails.getJwkSetUri()).isEqualTo("https://example.com/jwkset");
assertThat(registration.getClientAuthenticationMethod()).isEqualTo(ClientAuthenticationMethod.CLIENT_SECRET_BASIC);
assertThat(registration.getAuthorizationGrantType()).isEqualTo(AuthorizationGrantType.AUTHORIZATION_CODE);
assertThat(registration.getRedirectUri()).isEqualTo(DEFAULT_REDIRECT_URL);
assertThat(registration.getScopes()).containsOnly("openid", "profile", "email");
assertThat(registration.getClientName()).isEqualTo("Okta");
assertThat(registration.getRegistrationId()).isEqualTo("123");
}
use of org.springframework.security.oauth2.client.registration.ClientRegistration.ProviderDetails in project spring-security by spring-projects.
the class ClientRegistrationsBeanDefinitionParserTests method parseWhenIssuerUriConfiguredThenRequestConfigFromIssuer.
@Test
public void parseWhenIssuerUriConfiguredThenRequestConfigFromIssuer() throws Exception {
this.server = new MockWebServer();
this.server.start();
String serverUrl = this.server.url("/").toString();
String discoveryResponse = OIDC_DISCOVERY_RESPONSE.replace("${issuer-uri}", serverUrl);
this.server.enqueue(jsonResponse(discoveryResponse));
String contextConfig = ISSUER_URI_XML_CONFIG.replace("${issuer-uri}", serverUrl);
this.spring.context(contextConfig).autowire();
assertThat(this.clientRegistrationRepository).isInstanceOf(InMemoryClientRegistrationRepository.class);
ClientRegistration googleRegistration = this.clientRegistrationRepository.findByRegistrationId("google-login");
assertThat(googleRegistration).isNotNull();
assertThat(googleRegistration.getRegistrationId()).isEqualTo("google-login");
assertThat(googleRegistration.getClientId()).isEqualTo("google-client-id");
assertThat(googleRegistration.getClientSecret()).isEqualTo("google-client-secret");
assertThat(googleRegistration.getClientAuthenticationMethod()).isEqualTo(ClientAuthenticationMethod.CLIENT_SECRET_BASIC);
assertThat(googleRegistration.getAuthorizationGrantType()).isEqualTo(AuthorizationGrantType.AUTHORIZATION_CODE);
assertThat(googleRegistration.getRedirectUri()).isEqualTo("{baseUrl}/{action}/oauth2/code/{registrationId}");
assertThat(googleRegistration.getScopes()).isNull();
assertThat(googleRegistration.getClientName()).isEqualTo(serverUrl);
ProviderDetails googleProviderDetails = googleRegistration.getProviderDetails();
assertThat(googleProviderDetails).isNotNull();
assertThat(googleProviderDetails.getAuthorizationUri()).isEqualTo("https://example.com/o/oauth2/v2/auth");
assertThat(googleProviderDetails.getTokenUri()).isEqualTo("https://example.com/oauth2/v4/token");
assertThat(googleProviderDetails.getUserInfoEndpoint().getUri()).isEqualTo("https://example.com/oauth2/v3/userinfo");
assertThat(googleProviderDetails.getUserInfoEndpoint().getAuthenticationMethod()).isEqualTo(AuthenticationMethod.HEADER);
assertThat(googleProviderDetails.getUserInfoEndpoint().getUserNameAttributeName()).isEqualTo("sub");
assertThat(googleProviderDetails.getJwkSetUri()).isEqualTo("https://example.com/oauth2/v3/certs");
assertThat(googleProviderDetails.getIssuerUri()).isEqualTo(serverUrl);
}
use of org.springframework.security.oauth2.client.registration.ClientRegistration.ProviderDetails in project spring-security by spring-projects.
the class ClientRegistrationsBeanDefinitionParserTests method parseWhenMultipleClientsConfiguredThenAvailableInRepository.
@Test
public void parseWhenMultipleClientsConfiguredThenAvailableInRepository() {
this.spring.configLocations(ClientRegistrationsBeanDefinitionParserTests.xml("MultiClientRegistration")).autowire();
assertThat(this.clientRegistrationRepository).isInstanceOf(InMemoryClientRegistrationRepository.class);
ClientRegistration googleRegistration = this.clientRegistrationRepository.findByRegistrationId("google-login");
assertThat(googleRegistration).isNotNull();
assertThat(googleRegistration.getRegistrationId()).isEqualTo("google-login");
assertThat(googleRegistration.getClientId()).isEqualTo("google-client-id");
assertThat(googleRegistration.getClientSecret()).isEqualTo("google-client-secret");
assertThat(googleRegistration.getClientAuthenticationMethod()).isEqualTo(ClientAuthenticationMethod.CLIENT_SECRET_BASIC);
assertThat(googleRegistration.getAuthorizationGrantType()).isEqualTo(AuthorizationGrantType.AUTHORIZATION_CODE);
assertThat(googleRegistration.getRedirectUri()).isEqualTo("{baseUrl}/login/oauth2/code/{registrationId}");
assertThat(googleRegistration.getScopes()).isEqualTo(StringUtils.commaDelimitedListToSet("openid,profile,email"));
assertThat(googleRegistration.getClientName()).isEqualTo("Google");
ProviderDetails googleProviderDetails = googleRegistration.getProviderDetails();
assertThat(googleProviderDetails).isNotNull();
assertThat(googleProviderDetails.getAuthorizationUri()).isEqualTo("https://accounts.google.com/o/oauth2/v2/auth");
assertThat(googleProviderDetails.getTokenUri()).isEqualTo("https://www.googleapis.com/oauth2/v4/token");
assertThat(googleProviderDetails.getUserInfoEndpoint().getUri()).isEqualTo("https://www.googleapis.com/oauth2/v3/userinfo");
assertThat(googleProviderDetails.getUserInfoEndpoint().getAuthenticationMethod()).isEqualTo(AuthenticationMethod.HEADER);
assertThat(googleProviderDetails.getUserInfoEndpoint().getUserNameAttributeName()).isEqualTo("sub");
assertThat(googleProviderDetails.getJwkSetUri()).isEqualTo("https://www.googleapis.com/oauth2/v3/certs");
assertThat(googleProviderDetails.getIssuerUri()).isEqualTo("https://accounts.google.com");
ClientRegistration githubRegistration = this.clientRegistrationRepository.findByRegistrationId("github-login");
assertThat(githubRegistration).isNotNull();
assertThat(githubRegistration.getRegistrationId()).isEqualTo("github-login");
assertThat(githubRegistration.getClientId()).isEqualTo("github-client-id");
assertThat(githubRegistration.getClientSecret()).isEqualTo("github-client-secret");
assertThat(githubRegistration.getClientAuthenticationMethod()).isEqualTo(ClientAuthenticationMethod.CLIENT_SECRET_BASIC);
assertThat(githubRegistration.getAuthorizationGrantType()).isEqualTo(AuthorizationGrantType.AUTHORIZATION_CODE);
assertThat(githubRegistration.getRedirectUri()).isEqualTo("{baseUrl}/login/oauth2/code/{registrationId}");
assertThat(googleRegistration.getScopes()).isEqualTo(StringUtils.commaDelimitedListToSet("openid,profile,email"));
assertThat(githubRegistration.getClientName()).isEqualTo("Github");
ProviderDetails githubProviderDetails = githubRegistration.getProviderDetails();
assertThat(githubProviderDetails).isNotNull();
assertThat(githubProviderDetails.getAuthorizationUri()).isEqualTo("https://github.com/login/oauth/authorize");
assertThat(githubProviderDetails.getTokenUri()).isEqualTo("https://github.com/login/oauth/access_token");
assertThat(githubProviderDetails.getUserInfoEndpoint().getUri()).isEqualTo("https://api.github.com/user");
assertThat(githubProviderDetails.getUserInfoEndpoint().getAuthenticationMethod()).isEqualTo(AuthenticationMethod.HEADER);
assertThat(githubProviderDetails.getUserInfoEndpoint().getUserNameAttributeName()).isEqualTo("id");
}
Aggregations