use of org.springframework.security.oauth2.client.token.DefaultAccessTokenRequest 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.DefaultAccessTokenRequest in project spring-security-oauth by spring-projects.
the class RefreshTokenGrantTests method testConnectDirectlyToResourceServer.
@Test
public void testConnectDirectlyToResourceServer() throws Exception {
assertNotNull(existingToken.getRefreshToken());
// It won't be expired on the server, but we can force the client to refresh it
assertTrue(existingToken.isExpired());
AccessTokenRequest request = new DefaultAccessTokenRequest();
request.setExistingToken(existingToken);
OAuth2RestTemplate template = new OAuth2RestTemplate(resource, new DefaultOAuth2ClientContext(request));
String result = template.getForObject(serverRunning.getUrl("/sparklr2/photos/user/message"), String.class);
assertEquals("Hello, Trusted User marissa", result);
assertFalse("Tokens match so there was no refresh", existingToken.equals(template.getAccessToken()));
}
use of org.springframework.security.oauth2.client.token.DefaultAccessTokenRequest in project spring-security-oauth by spring-projects.
the class OAuth2ContextSetup method starting.
@Override
public void starting(FrameworkMethod method) {
if (resource != null) {
logger.info("Starting OAuth2 context for: " + resource);
AccessTokenRequest request = new DefaultAccessTokenRequest();
request.setAll(parameters);
client = createRestTemplate(resource, request);
if (initializeAccessToken) {
this.accessToken = null;
this.accessToken = getAccessToken();
}
savedClient = clientHolder.getRestTemplate();
clientHolder.setRestTemplate(client);
}
}
use of org.springframework.security.oauth2.client.token.DefaultAccessTokenRequest in project spring-security-oauth by spring-projects.
the class OAuth2ClientConfiguration method accessTokenRequest.
@Bean
@Scope(value = "request", proxyMode = ScopedProxyMode.INTERFACES)
protected AccessTokenRequest accessTokenRequest(@Value("#{request.parameterMap}") Map<String, String[]> parameters, @Value("#{request.getAttribute('currentUri')}") String currentUri) {
DefaultAccessTokenRequest request = new DefaultAccessTokenRequest(parameters);
request.setCurrentUri(currentUri);
return request;
}
use of org.springframework.security.oauth2.client.token.DefaultAccessTokenRequest in project spring-security-oauth by spring-projects.
the class AuthorizationCodeAccessTokenProviderTests method testGetAccessTokenFailsWithNoState.
@Test
public void testGetAccessTokenFailsWithNoState() throws Exception {
AccessTokenRequest request = new DefaultAccessTokenRequest();
request.setAuthorizationCode("foo");
resource.setAccessTokenUri("http://localhost/oauth/token");
expected.expect(InvalidRequestException.class);
assertEquals("FOO", provider.obtainAccessToken(resource, request).getValue());
}
Aggregations