use of org.springframework.security.oauth2.client.OAuth2AuthorizedClientProvider in project spring-security by spring-projects.
the class DelegatingOAuth2AuthorizedClientProviderTests method authorizeWhenProviderCanAuthorizeThenReturnAuthorizedClient.
@Test
public void authorizeWhenProviderCanAuthorizeThenReturnAuthorizedClient() {
Authentication principal = new TestingAuthenticationToken("principal", "password");
ClientRegistration clientRegistration = TestClientRegistrations.clientRegistration().build();
OAuth2AuthorizedClient authorizedClient = new OAuth2AuthorizedClient(clientRegistration, principal.getName(), TestOAuth2AccessTokens.noScopes());
OAuth2AuthorizedClientProvider authorizedClientProvider = mock(OAuth2AuthorizedClientProvider.class);
given(authorizedClientProvider.authorize(any())).willReturn(authorizedClient);
DelegatingOAuth2AuthorizedClientProvider delegate = new DelegatingOAuth2AuthorizedClientProvider(mock(OAuth2AuthorizedClientProvider.class), mock(OAuth2AuthorizedClientProvider.class), authorizedClientProvider);
OAuth2AuthorizationContext context = OAuth2AuthorizationContext.withClientRegistration(clientRegistration).principal(principal).build();
OAuth2AuthorizedClient reauthorizedClient = delegate.authorize(context);
assertThat(reauthorizedClient).isSameAs(authorizedClient);
}
Aggregations