use of org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientProperties.Provider in project spring-boot by spring-projects.
the class OAuth2ClientPropertiesRegistrationAdapterTests method getClientRegistrationsWhenUsingDefinedProviderShouldAdapt.
@Test
void getClientRegistrationsWhenUsingDefinedProviderShouldAdapt() {
OAuth2ClientProperties properties = new OAuth2ClientProperties();
Provider provider = createProvider();
provider.setUserInfoAuthenticationMethod("form");
OAuth2ClientProperties.Registration registration = createRegistration("provider");
registration.setClientName("clientName");
properties.getRegistration().put("registration", registration);
properties.getProvider().put("provider", provider);
Map<String, ClientRegistration> registrations = OAuth2ClientPropertiesRegistrationAdapter.getClientRegistrations(properties);
ClientRegistration adapted = registrations.get("registration");
ProviderDetails adaptedProvider = adapted.getProviderDetails();
assertThat(adaptedProvider.getAuthorizationUri()).isEqualTo("https://example.com/auth");
assertThat(adaptedProvider.getTokenUri()).isEqualTo("https://example.com/token");
UserInfoEndpoint userInfoEndpoint = adaptedProvider.getUserInfoEndpoint();
assertThat(userInfoEndpoint.getUri()).isEqualTo("https://example.com/info");
assertThat(userInfoEndpoint.getAuthenticationMethod()).isEqualTo(org.springframework.security.oauth2.core.AuthenticationMethod.FORM);
assertThat(userInfoEndpoint.getUserNameAttributeName()).isEqualTo("sub");
assertThat(adaptedProvider.getJwkSetUri()).isEqualTo("https://example.com/jwk");
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.Provider 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.Provider in project spring-boot by spring-projects.
the class OAuth2ClientPropertiesRegistrationAdapterTests method createProvider.
private Provider createProvider() {
Provider provider = new Provider();
provider.setAuthorizationUri("https://example.com/auth");
provider.setTokenUri("https://example.com/token");
provider.setUserInfoUri("https://example.com/info");
provider.setUserNameAttribute("sub");
provider.setJwkSetUri("https://example.com/jwk");
return provider;
}
use of org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientProperties.Provider in project spring-boot by spring-projects.
the class OAuth2ClientPropertiesRegistrationAdapter method getBuilderFromIssuerIfPossible.
private static Builder getBuilderFromIssuerIfPossible(String registrationId, String configuredProviderId, Map<String, Provider> providers) {
String providerId = (configuredProviderId != null) ? configuredProviderId : registrationId;
if (providers.containsKey(providerId)) {
Provider provider = providers.get(providerId);
String issuer = provider.getIssuerUri();
if (issuer != null) {
Builder builder = ClientRegistrations.fromIssuerLocation(issuer).registrationId(registrationId);
return getBuilder(builder, provider);
}
}
return null;
}
use of org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientProperties.Provider 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'");
}
Aggregations