Search in sources :

Example 6 with Registration

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");
}
Also used : ClientRegistration(org.springframework.security.oauth2.client.registration.ClientRegistration) Registration(org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientProperties.Registration) UserInfoEndpoint(org.springframework.security.oauth2.client.registration.ClientRegistration.ProviderDetails.UserInfoEndpoint) ProviderDetails(org.springframework.security.oauth2.client.registration.ClientRegistration.ProviderDetails) Test(org.junit.jupiter.api.Test)

Example 7 with Registration

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'");
}
Also used : ClientRegistration(org.springframework.security.oauth2.client.registration.ClientRegistration) Registration(org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientProperties.Registration) Registration(org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientProperties.Registration) Test(org.junit.jupiter.api.Test)

Example 8 with Registration

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);
}
Also used : ClientRegistration(org.springframework.security.oauth2.client.registration.ClientRegistration) Registration(org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientProperties.Registration) Test(org.junit.jupiter.api.Test)

Example 9 with Registration

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'");
}
Also used : ClientRegistration(org.springframework.security.oauth2.client.registration.ClientRegistration) Registration(org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientProperties.Registration) Registration(org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientProperties.Registration) Test(org.junit.jupiter.api.Test)

Example 10 with Registration

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;
}
Also used : ClientRegistration(org.springframework.security.oauth2.client.registration.ClientRegistration) Registration(org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientProperties.Registration) Registration(org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientProperties.Registration)

Aggregations

ClientRegistration (org.springframework.security.oauth2.client.registration.ClientRegistration)13 Registration (org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientProperties.Registration)12 Test (org.junit.jupiter.api.Test)11 ProviderDetails (org.springframework.security.oauth2.client.registration.ClientRegistration.ProviderDetails)6 UserInfoEndpoint (org.springframework.security.oauth2.client.registration.ClientRegistration.ProviderDetails.UserInfoEndpoint)6 Provider (org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientProperties.Provider)3 MockWebServer (okhttp3.mockwebserver.MockWebServer)2