use of org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsResourceDetails in project spring-security-oauth by spring-projects.
the class AccessTokenProviderChainTests method testSunnyDayClientCredentialsWithTokenServicesSave.
@Test
public void testSunnyDayClientCredentialsWithTokenServicesSave() throws Exception {
AccessTokenProviderChain chain = new AccessTokenProviderChain(Arrays.asList(new StubAccessTokenProvider()));
chain.setClientTokenServices(clientTokenServices);
AccessTokenRequest request = new DefaultAccessTokenRequest();
resource = new ClientCredentialsResourceDetails();
resource.setId("resource");
OAuth2AccessToken token = chain.obtainAccessToken(resource, request);
assertNotNull(token);
Mockito.verify(clientTokenServices).saveAccessToken(resource, null, token);
}
use of org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsResourceDetails in project spring-security-oauth by spring-projects.
the class ClientCredentialsGrantTests method testConnectDirectlyToResourceServer.
@Test
public void testConnectDirectlyToResourceServer() throws Exception {
ClientCredentialsResourceDetails resource = new ClientCredentialsResourceDetails();
resource.setAccessTokenUri(serverRunning.getUrl("/sparklr2/oauth/token"));
resource.setClientId("my-client-with-registered-redirect");
resource.setId("sparklr");
resource.setScope(Arrays.asList("trust"));
ClientCredentialsAccessTokenProvider provider = new ClientCredentialsAccessTokenProvider();
OAuth2AccessToken accessToken = provider.obtainAccessToken(resource, new DefaultAccessTokenRequest());
OAuth2RestTemplate template = new OAuth2RestTemplate(resource, new DefaultOAuth2ClientContext(accessToken));
String result = template.getForObject(serverRunning.getUrl("/sparklr2/photos/trusted/message"), String.class);
assertEquals("Hello, Trusted Client", result);
}
use of org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsResourceDetails in project faf-java-server by FAForever.
the class ApiConfig method restTemplate.
@Bean
public RestTemplate restTemplate(RestTemplateBuilder restTemplateBuilder, JsonApiMessageConverter jsonApiMessageConverter, ServerProperties properties) throws IOException {
Api api = properties.getApi();
ClientCredentialsResourceDetails resourceDetails = new ClientCredentialsResourceDetails();
resourceDetails.setClientId(api.getClientId());
resourceDetails.setClientSecret(api.getClientSecret());
resourceDetails.setAccessTokenUri(api.getAccessTokenUri());
return restTemplateBuilder.additionalMessageConverters(jsonApiMessageConverter).rootUri(api.getBaseUrl()).configure(new OAuth2RestTemplate(resourceDetails));
}
use of org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsResourceDetails in project tutorials by eugenp.
the class CustomConfigAuthorizationServerIntegrationTest method givenOAuth2Context_whenAccessTokenIsRequestedWithInvalidException_ThenExceptionIsThrown.
@Test(expected = OAuth2AccessDeniedException.class)
public void givenOAuth2Context_whenAccessTokenIsRequestedWithInvalidException_ThenExceptionIsThrown() {
ClientCredentialsResourceDetails resourceDetails = getClientCredentialsResourceDetails("baeldung", singletonList("write"));
OAuth2RestTemplate restTemplate = getOAuth2RestTemplate(resourceDetails);
restTemplate.getAccessToken();
}
use of org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsResourceDetails in project tutorials by eugenp.
the class DefaultConfigAuthorizationServerIntegrationTest method givenOAuth2Context_whenAccessTokenIsRequested_ThenAccessTokenValueIsNotNull.
@Test
public void givenOAuth2Context_whenAccessTokenIsRequested_ThenAccessTokenValueIsNotNull() {
ClientCredentialsResourceDetails resourceDetails = getClientCredentialsResourceDetails("client", asList("read", "write"));
OAuth2RestTemplate restTemplate = getOAuth2RestTemplate(resourceDetails);
OAuth2AccessToken accessToken = restTemplate.getAccessToken();
assertNotNull(accessToken);
}
Aggregations