use of org.springframework.security.oauth2.client.registration.ClientRegistrationRepository in project spring-security by spring-projects.
the class OAuth2ClientConfigurerTests method setup.
@BeforeEach
public void setup() {
// @formatter:off
this.registration1 = TestClientRegistrations.clientRegistration().registrationId("registration-1").clientId("client-1").clientSecret("secret").clientAuthenticationMethod(ClientAuthenticationMethod.CLIENT_SECRET_BASIC).authorizationGrantType(AuthorizationGrantType.AUTHORIZATION_CODE).redirectUri("{baseUrl}/client-1").scope("user").authorizationUri("https://provider.com/oauth2/authorize").tokenUri("https://provider.com/oauth2/token").userInfoUri("https://provider.com/oauth2/user").userNameAttributeName("id").clientName("client-1").build();
// @formatter:on
clientRegistrationRepository = new InMemoryClientRegistrationRepository(this.registration1);
authorizedClientService = new InMemoryOAuth2AuthorizedClientService(clientRegistrationRepository);
authorizedClientRepository = new AuthenticatedPrincipalOAuth2AuthorizedClientRepository(authorizedClientService);
authorizationRequestResolver = new DefaultOAuth2AuthorizationRequestResolver(clientRegistrationRepository, "/oauth2/authorization");
OAuth2AccessTokenResponse accessTokenResponse = OAuth2AccessTokenResponse.withToken("access-token-1234").tokenType(OAuth2AccessToken.TokenType.BEARER).expiresIn(300).build();
accessTokenResponseClient = mock(OAuth2AccessTokenResponseClient.class);
given(accessTokenResponseClient.getTokenResponse(any(OAuth2AuthorizationCodeGrantRequest.class))).willReturn(accessTokenResponse);
requestCache = mock(RequestCache.class);
}
use of org.springframework.security.oauth2.client.registration.ClientRegistrationRepository in project spring-boot by spring-projects.
the class OAuth2WebSecurityConfigurationTests method securityConfigurerConfiguresAuthorizationCode.
@Test
void securityConfigurerConfiguresAuthorizationCode() {
this.contextRunner.withUserConfiguration(ClientRegistrationRepositoryConfiguration.class, OAuth2WebSecurityConfiguration.class).run((context) -> {
ClientRegistrationRepository expected = context.getBean(ClientRegistrationRepository.class);
ClientRegistrationRepository actual = (ClientRegistrationRepository) ReflectionTestUtils.getField(getFilters(context, OAuth2AuthorizationCodeGrantFilter.class).get(0), "clientRegistrationRepository");
assertThat(isEqual(expected.findByRegistrationId("first"), actual.findByRegistrationId("first"))).isTrue();
assertThat(isEqual(expected.findByRegistrationId("second"), actual.findByRegistrationId("second"))).isTrue();
});
}
use of org.springframework.security.oauth2.client.registration.ClientRegistrationRepository in project spring-boot by spring-projects.
the class OAuth2WebSecurityConfigurationTests method securityConfigurerConfiguresOAuth2Login.
@Test
void securityConfigurerConfiguresOAuth2Login() {
this.contextRunner.withUserConfiguration(ClientRegistrationRepositoryConfiguration.class, OAuth2WebSecurityConfiguration.class).run((context) -> {
ClientRegistrationRepository expected = context.getBean(ClientRegistrationRepository.class);
ClientRegistrationRepository actual = (ClientRegistrationRepository) ReflectionTestUtils.getField(getFilters(context, OAuth2LoginAuthenticationFilter.class).get(0), "clientRegistrationRepository");
assertThat(isEqual(expected.findByRegistrationId("first"), actual.findByRegistrationId("first"))).isTrue();
assertThat(isEqual(expected.findByRegistrationId("second"), actual.findByRegistrationId("second"))).isTrue();
});
}
use of org.springframework.security.oauth2.client.registration.ClientRegistrationRepository in project spring-boot by spring-projects.
the class OAuth2ClientRegistrationRepositoryConfigurationTests method clientRegistrationRepositoryBeanShouldBeCreatedWhenPropertiesPresent.
@Test
void clientRegistrationRepositoryBeanShouldBeCreatedWhenPropertiesPresent() {
this.contextRunner.withUserConfiguration(OAuth2ClientRegistrationRepositoryConfiguration.class).withPropertyValues(REGISTRATION_PREFIX + ".foo.client-id=abcd", REGISTRATION_PREFIX + ".foo.client-secret=secret", REGISTRATION_PREFIX + ".foo.provider=github").run((context) -> {
ClientRegistrationRepository repository = context.getBean(ClientRegistrationRepository.class);
ClientRegistration registration = repository.findByRegistrationId("foo");
assertThat(registration).isNotNull();
assertThat(registration.getClientSecret()).isEqualTo("secret");
});
}
use of org.springframework.security.oauth2.client.registration.ClientRegistrationRepository in project tutorials by eugenp.
the class LoginController method getLoginPage.
@GetMapping("/oauth_login")
public String getLoginPage(Model model) {
Iterable<ClientRegistration> clientRegistrations = null;
ResolvableType type = ResolvableType.forInstance(clientRegistrationRepository).as(Iterable.class);
if (type != ResolvableType.NONE && ClientRegistration.class.isAssignableFrom(type.resolveGenerics()[0])) {
clientRegistrations = (Iterable<ClientRegistration>) clientRegistrationRepository;
}
clientRegistrations.forEach(registration -> oauth2AuthenticationUrls.put(registration.getClientName(), authorizationRequestBaseUri + "/" + registration.getRegistrationId()));
model.addAttribute("urls", oauth2AuthenticationUrls);
return "oauth_login";
}
Aggregations