Search in sources :

Example 26 with AuthorizationGrantType

use of org.springframework.security.oauth2.core.AuthorizationGrantType in project spring-security by spring-projects.

the class ClientRegistrationTests method buildWhenCustomClientAuthenticationMethodProvidedThenSet.

// gh-8903
@Test
public void buildWhenCustomClientAuthenticationMethodProvidedThenSet() {
    ClientAuthenticationMethod clientAuthenticationMethod = new ClientAuthenticationMethod("tls_client_auth");
    // @formatter:off
    ClientRegistration clientRegistration = ClientRegistration.withRegistrationId(REGISTRATION_ID).clientId(CLIENT_ID).authorizationGrantType(AuthorizationGrantType.AUTHORIZATION_CODE).clientAuthenticationMethod(clientAuthenticationMethod).redirectUri(REDIRECT_URI).authorizationUri(AUTHORIZATION_URI).tokenUri(TOKEN_URI).build();
    // @formatter:on
    assertThat(clientRegistration.getClientAuthenticationMethod()).isEqualTo(clientAuthenticationMethod);
}
Also used : ClientAuthenticationMethod(org.springframework.security.oauth2.core.ClientAuthenticationMethod) Test(org.junit.jupiter.api.Test)

Example 27 with AuthorizationGrantType

use of org.springframework.security.oauth2.core.AuthorizationGrantType in project spring-security by spring-projects.

the class ClientRegistrationTests method buildWhenCustomGrantAllAttributesProvidedThenAllAttributesAreSet.

@Test
public void buildWhenCustomGrantAllAttributesProvidedThenAllAttributesAreSet() {
    AuthorizationGrantType customGrantType = new AuthorizationGrantType("CUSTOM");
    // @formatter:off
    ClientRegistration registration = ClientRegistration.withRegistrationId(REGISTRATION_ID).clientId(CLIENT_ID).clientSecret(CLIENT_SECRET).clientAuthenticationMethod(ClientAuthenticationMethod.CLIENT_SECRET_BASIC).authorizationGrantType(customGrantType).scope(SCOPES.toArray(new String[0])).tokenUri(TOKEN_URI).clientName(CLIENT_NAME).build();
    // @formatter:on
    assertThat(registration.getRegistrationId()).isEqualTo(REGISTRATION_ID);
    assertThat(registration.getClientId()).isEqualTo(CLIENT_ID);
    assertThat(registration.getClientSecret()).isEqualTo(CLIENT_SECRET);
    assertThat(registration.getClientAuthenticationMethod()).isEqualTo(ClientAuthenticationMethod.CLIENT_SECRET_BASIC);
    assertThat(registration.getAuthorizationGrantType()).isEqualTo(customGrantType);
    assertThat(registration.getScopes()).isEqualTo(SCOPES);
    assertThat(registration.getProviderDetails().getTokenUri()).isEqualTo(TOKEN_URI);
    assertThat(registration.getClientName()).isEqualTo(CLIENT_NAME);
}
Also used : AuthorizationGrantType(org.springframework.security.oauth2.core.AuthorizationGrantType) Test(org.junit.jupiter.api.Test)

Example 28 with AuthorizationGrantType

use of org.springframework.security.oauth2.core.AuthorizationGrantType in project spring-boot by spring-projects.

the class OAuth2ClientPropertiesRegistrationAdapter method getClientRegistration.

private static ClientRegistration getClientRegistration(String registrationId, OAuth2ClientProperties.Registration properties, Map<String, Provider> providers) {
    Builder builder = getBuilderFromIssuerIfPossible(registrationId, properties.getProvider(), providers);
    if (builder == null) {
        builder = getBuilder(registrationId, properties.getProvider(), providers);
    }
    PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
    map.from(properties::getClientId).to(builder::clientId);
    map.from(properties::getClientSecret).to(builder::clientSecret);
    map.from(properties::getClientAuthenticationMethod).as(ClientAuthenticationMethod::new).to(builder::clientAuthenticationMethod);
    map.from(properties::getAuthorizationGrantType).as(AuthorizationGrantType::new).to(builder::authorizationGrantType);
    map.from(properties::getRedirectUri).to(builder::redirectUri);
    map.from(properties::getScope).as(StringUtils::toStringArray).to(builder::scope);
    map.from(properties::getClientName).to(builder::clientName);
    return builder.build();
}
Also used : Builder(org.springframework.security.oauth2.client.registration.ClientRegistration.Builder) PropertyMapper(org.springframework.boot.context.properties.PropertyMapper)

Aggregations

ClientRegistration (org.springframework.security.oauth2.client.registration.ClientRegistration)15 Test (org.junit.jupiter.api.Test)10 BeforeEach (org.junit.jupiter.api.BeforeEach)7 Jwt (org.springframework.security.oauth2.jwt.Jwt)7 AuthorizationGrantType (org.springframework.security.oauth2.core.AuthorizationGrantType)6 OAuth2AccessTokenResponse (org.springframework.security.oauth2.core.endpoint.OAuth2AccessTokenResponse)6 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)5 ReactiveOAuth2AccessTokenResponseClient (org.springframework.security.oauth2.client.endpoint.ReactiveOAuth2AccessTokenResponseClient)4 Clock (java.time.Clock)3 Duration (java.time.Duration)3 Instant (java.time.Instant)3 LinkedHashMap (java.util.LinkedHashMap)3 Nullable (org.springframework.lang.Nullable)3 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)3 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)3 Authentication (org.springframework.security.core.Authentication)3 InMemoryClientRegistrationRepository (org.springframework.security.oauth2.client.registration.InMemoryClientRegistrationRepository)3 OAuth2AuthorizationException (org.springframework.security.oauth2.core.OAuth2AuthorizationException)3 OAuth2Token (org.springframework.security.oauth2.core.OAuth2Token)3 Assert (org.springframework.util.Assert)3