Search in sources :

Example 21 with AuthorizationGrantType

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

the class JwtBearerReactiveOAuth2AuthorizedClientProviderTests method setup.

@BeforeEach
public void setup() {
    this.authorizedClientProvider = new JwtBearerReactiveOAuth2AuthorizedClientProvider();
    this.accessTokenResponseClient = mock(ReactiveOAuth2AccessTokenResponseClient.class);
    this.authorizedClientProvider.setAccessTokenResponseClient(this.accessTokenResponseClient);
    // @formatter:off
    this.clientRegistration = ClientRegistration.withRegistrationId("jwt-bearer").clientId("client-id").clientSecret("client-secret").clientAuthenticationMethod(ClientAuthenticationMethod.CLIENT_SECRET_BASIC).authorizationGrantType(AuthorizationGrantType.JWT_BEARER).scope("read", "write").tokenUri("https://example.com/oauth2/token").build();
    // @formatter:on
    this.jwtAssertion = TestJwts.jwt().build();
    this.principal = new TestingAuthenticationToken(this.jwtAssertion, this.jwtAssertion);
}
Also used : TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) ReactiveOAuth2AccessTokenResponseClient(org.springframework.security.oauth2.client.endpoint.ReactiveOAuth2AccessTokenResponseClient) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 22 with AuthorizationGrantType

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

the class OAuth2AuthorizationRequestDeserializer method deserialize.

private OAuth2AuthorizationRequest deserialize(JsonParser parser, ObjectMapper mapper, JsonNode root) throws JsonParseException {
    AuthorizationGrantType authorizationGrantType = AUTHORIZATION_GRANT_TYPE_CONVERTER.convert(JsonNodeUtils.findObjectNode(root, "authorizationGrantType"));
    Builder builder = getBuilder(parser, authorizationGrantType);
    builder.authorizationUri(JsonNodeUtils.findStringValue(root, "authorizationUri"));
    builder.clientId(JsonNodeUtils.findStringValue(root, "clientId"));
    builder.redirectUri(JsonNodeUtils.findStringValue(root, "redirectUri"));
    builder.scopes(JsonNodeUtils.findValue(root, "scopes", JsonNodeUtils.STRING_SET, mapper));
    builder.state(JsonNodeUtils.findStringValue(root, "state"));
    builder.additionalParameters(JsonNodeUtils.findValue(root, "additionalParameters", JsonNodeUtils.STRING_OBJECT_MAP, mapper));
    builder.authorizationRequestUri(JsonNodeUtils.findStringValue(root, "authorizationRequestUri"));
    builder.attributes(JsonNodeUtils.findValue(root, "attributes", JsonNodeUtils.STRING_OBJECT_MAP, mapper));
    return builder.build();
}
Also used : AuthorizationGrantType(org.springframework.security.oauth2.core.AuthorizationGrantType) Builder(org.springframework.security.oauth2.core.endpoint.OAuth2AuthorizationRequest.Builder)

Example 23 with AuthorizationGrantType

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

the class OAuth2AuthorizedClientMixinTests method setup.

@BeforeEach
public void setup() {
    ClassLoader loader = getClass().getClassLoader();
    this.mapper = new ObjectMapper();
    this.mapper.registerModules(SecurityJackson2Modules.getModules(loader));
    Map<String, Object> providerConfigurationMetadata = new LinkedHashMap<>();
    providerConfigurationMetadata.put("config1", "value1");
    providerConfigurationMetadata.put("config2", "value2");
    // @formatter:off
    this.clientRegistrationBuilder = TestClientRegistrations.clientRegistration().authorizationGrantType(new AuthorizationGrantType("custom-grant")).scope("read", "write").providerConfigurationMetadata(providerConfigurationMetadata);
    // @formatter:on
    this.accessToken = TestOAuth2AccessTokens.scopes("read", "write");
    this.refreshToken = TestOAuth2RefreshTokens.refreshToken();
    this.principalName = "principal-name";
}
Also used : AuthorizationGrantType(org.springframework.security.oauth2.core.AuthorizationGrantType) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) LinkedHashMap(java.util.LinkedHashMap) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 24 with AuthorizationGrantType

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

the class OAuth2AuthorizationRequestMixinTests method deserializeWhenInvalidAuthorizationGrantTypeThenThrowJsonParseException.

@Test
public void deserializeWhenInvalidAuthorizationGrantTypeThenThrowJsonParseException() {
    OAuth2AuthorizationRequest authorizationRequest = this.authorizationRequestBuilder.build();
    String json = asJson(authorizationRequest).replace("authorization_code", "client_credentials");
    assertThatExceptionOfType(JsonParseException.class).isThrownBy(() -> this.mapper.readValue(json, OAuth2AuthorizationRequest.class)).withMessageContaining("Invalid authorizationGrantType");
}
Also used : OAuth2AuthorizationRequest(org.springframework.security.oauth2.core.endpoint.OAuth2AuthorizationRequest) Test(org.junit.jupiter.api.Test)

Example 25 with AuthorizationGrantType

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

the class OAuth2UserRequestTests method setUp.

@BeforeEach
public void setUp() {
    // @formatter:off
    this.clientRegistration = ClientRegistration.withRegistrationId("registration-1").clientId("client-1").clientSecret("secret").clientAuthenticationMethod(ClientAuthenticationMethod.CLIENT_SECRET_BASIC).authorizationGrantType(AuthorizationGrantType.AUTHORIZATION_CODE).redirectUri("https://client.com").scope(new LinkedHashSet<>(Arrays.asList("scope1", "scope2"))).authorizationUri("https://provider.com/oauth2/authorization").tokenUri("https://provider.com/oauth2/token").clientName("Client 1").build();
    // @formatter:on
    this.accessToken = new OAuth2AccessToken(OAuth2AccessToken.TokenType.BEARER, "access-token-1234", Instant.now(), Instant.now().plusSeconds(60), new LinkedHashSet<>(Arrays.asList("scope1", "scope2")));
    this.additionalParameters = new HashMap<>();
    this.additionalParameters.put("param1", "value1");
    this.additionalParameters.put("param2", "value2");
}
Also used : LinkedHashSet(java.util.LinkedHashSet) OAuth2AccessToken(org.springframework.security.oauth2.core.OAuth2AccessToken) BeforeEach(org.junit.jupiter.api.BeforeEach)

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