use of org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientProperties.Registration in project spring-boot by spring-projects.
the class OAuth2ClientPropertiesRegistrationAdapterTests method getClientRegistrationsWhenUsingCommonProviderWithOverrideShouldAdapt.
@Test
void getClientRegistrationsWhenUsingCommonProviderWithOverrideShouldAdapt() {
OAuth2ClientProperties properties = new OAuth2ClientProperties();
OAuth2ClientProperties.Registration registration = createRegistration("google");
registration.setClientName("clientName");
properties.getRegistration().put("registration", registration);
Map<String, ClientRegistration> registrations = OAuth2ClientPropertiesRegistrationAdapter.getClientRegistrations(properties);
ClientRegistration adapted = registrations.get("registration");
ProviderDetails adaptedProvider = adapted.getProviderDetails();
assertThat(adaptedProvider.getAuthorizationUri()).isEqualTo("https://accounts.google.com/o/oauth2/v2/auth");
assertThat(adaptedProvider.getTokenUri()).isEqualTo("https://www.googleapis.com/oauth2/v4/token");
UserInfoEndpoint userInfoEndpoint = adaptedProvider.getUserInfoEndpoint();
assertThat(userInfoEndpoint.getUri()).isEqualTo("https://www.googleapis.com/oauth2/v3/userinfo");
assertThat(userInfoEndpoint.getUserNameAttributeName()).isEqualTo(IdTokenClaimNames.SUB);
assertThat(userInfoEndpoint.getAuthenticationMethod()).isEqualTo(org.springframework.security.oauth2.core.AuthenticationMethod.HEADER);
assertThat(adaptedProvider.getJwkSetUri()).isEqualTo("https://www.googleapis.com/oauth2/v3/certs");
assertThat(adapted.getRegistrationId()).isEqualTo("registration");
assertThat(adapted.getClientId()).isEqualTo("clientId");
assertThat(adapted.getClientSecret()).isEqualTo("clientSecret");
assertThat(adapted.getClientAuthenticationMethod()).isEqualTo(org.springframework.security.oauth2.core.ClientAuthenticationMethod.CLIENT_SECRET_POST);
assertThat(adapted.getAuthorizationGrantType()).isEqualTo(org.springframework.security.oauth2.core.AuthorizationGrantType.AUTHORIZATION_CODE);
assertThat(adapted.getRedirectUri()).isEqualTo("https://example.com/redirect");
assertThat(adapted.getScopes()).containsExactly("user");
assertThat(adapted.getClientName()).isEqualTo("clientName");
}
use of org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientProperties.Registration in project spring-boot by spring-projects.
the class OAuth2ClientPropertiesRegistrationAdapterTests method getClientRegistrationsWhenUnknownProviderShouldThrowException.
@Test
void getClientRegistrationsWhenUnknownProviderShouldThrowException() {
OAuth2ClientProperties properties = new OAuth2ClientProperties();
OAuth2ClientProperties.Registration registration = new OAuth2ClientProperties.Registration();
registration.setProvider("missing");
properties.getRegistration().put("registration", registration);
assertThatIllegalStateException().isThrownBy(() -> OAuth2ClientPropertiesRegistrationAdapter.getClientRegistrations(properties)).withMessageContaining("Unknown provider ID 'missing'");
}
use of org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientProperties.Registration in project spring-boot by spring-projects.
the class OAuth2ClientPropertiesRegistrationAdapterTests method oidcProviderConfigurationWhenProviderNotSpecifiedOnRegistration.
@Test
void oidcProviderConfigurationWhenProviderNotSpecifiedOnRegistration() throws Exception {
Registration login = new OAuth2ClientProperties.Registration();
login.setClientId("clientId");
login.setClientSecret("clientSecret");
testIssuerConfiguration(login, "okta", 0, 1);
}
use of org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientProperties.Registration in project spring-boot by spring-projects.
the class OAuth2ClientPropertiesRegistrationAdapterTests method getClientRegistrationsWhenProviderNotSpecifiedAndUnknownProviderShouldThrowException.
@Test
void getClientRegistrationsWhenProviderNotSpecifiedAndUnknownProviderShouldThrowException() {
OAuth2ClientProperties properties = new OAuth2ClientProperties();
OAuth2ClientProperties.Registration registration = new OAuth2ClientProperties.Registration();
properties.getRegistration().put("missing", registration);
assertThatIllegalStateException().isThrownBy(() -> OAuth2ClientPropertiesRegistrationAdapter.getClientRegistrations(properties)).withMessageContaining("Provider ID must be specified for client registration 'missing'");
}
use of org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientProperties.Registration in project spring-boot by spring-projects.
the class OAuth2ClientPropertiesRegistrationAdapterTests method createRegistration.
private OAuth2ClientProperties.Registration createRegistration(String provider) {
OAuth2ClientProperties.Registration registration = new OAuth2ClientProperties.Registration();
registration.setProvider(provider);
registration.setClientId("clientId");
registration.setClientSecret("clientSecret");
registration.setClientAuthenticationMethod("client_secret_post");
registration.setRedirectUri("https://example.com/redirect");
registration.setScope(Collections.singleton("user"));
registration.setAuthorizationGrantType("authorization_code");
return registration;
}
Aggregations