Search in sources :

Example 21 with ClientAuthenticationMethod

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

the class DefaultOAuth2AuthorizationRequestResolverTests method setUp.

@BeforeEach
public void setUp() {
    this.registration1 = TestClientRegistrations.clientRegistration().build();
    this.registration2 = TestClientRegistrations.clientRegistration2().build();
    this.fineRedirectUriTemplateRegistration = fineRedirectUriTemplateClientRegistration().build();
    // @formatter:off
    this.pkceRegistration = TestClientRegistrations.clientRegistration().registrationId("pkce-client-registration-id").clientId("pkce-client-id").clientAuthenticationMethod(ClientAuthenticationMethod.NONE).clientSecret(null).build();
    this.oidcRegistration = TestClientRegistrations.clientRegistration().registrationId("oidc-registration-id").scope(OidcScopes.OPENID).build();
    // @formatter:on
    this.clientRegistrationRepository = new InMemoryClientRegistrationRepository(this.registration1, this.registration2, this.fineRedirectUriTemplateRegistration, this.pkceRegistration, this.oidcRegistration);
    this.resolver = new DefaultOAuth2AuthorizationRequestResolver(this.clientRegistrationRepository, this.authorizationRequestBaseUri);
}
Also used : InMemoryClientRegistrationRepository(org.springframework.security.oauth2.client.registration.InMemoryClientRegistrationRepository) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 22 with ClientAuthenticationMethod

use of org.springframework.security.oauth2.core.ClientAuthenticationMethod 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 23 with ClientAuthenticationMethod

use of org.springframework.security.oauth2.core.ClientAuthenticationMethod 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)

Aggregations

Test (org.junit.jupiter.api.Test)12 ClientRegistration (org.springframework.security.oauth2.client.registration.ClientRegistration)11 BeforeEach (org.junit.jupiter.api.BeforeEach)7 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)5 InMemoryClientRegistrationRepository (org.springframework.security.oauth2.client.registration.InMemoryClientRegistrationRepository)4 Jwt (org.springframework.security.oauth2.jwt.Jwt)4 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)3 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)3 Authentication (org.springframework.security.core.Authentication)3 OAuth2AccessTokenResponse (org.springframework.security.oauth2.core.endpoint.OAuth2AccessTokenResponse)3 NimbusJwtDecoder (org.springframework.security.oauth2.jwt.NimbusJwtDecoder)3 RSAKey (com.nimbusds.jose.jwk.RSAKey)2 HttpServletRequest (jakarta.servlet.http.HttpServletRequest)2 OAuth2AccessTokenResponseClient (org.springframework.security.oauth2.client.endpoint.OAuth2AccessTokenResponseClient)2 ClientAuthenticationMethod (org.springframework.security.oauth2.core.ClientAuthenticationMethod)2 OAuth2AuthorizationExchange (org.springframework.security.oauth2.core.endpoint.OAuth2AuthorizationExchange)2 OAuth2AuthorizationRequest (org.springframework.security.oauth2.core.endpoint.OAuth2AuthorizationRequest)2 EncryptionException (com.evolveum.midpoint.prism.crypto.EncryptionException)1 OctetSequenceKey (com.nimbusds.jose.jwk.OctetSequenceKey)1 FilterChain (jakarta.servlet.FilterChain)1