use of org.springframework.security.oauth2.client.token.DefaultAccessTokenRequest 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.DefaultAccessTokenRequest in project spring-security-oauth by spring-projects.
the class AuthorizationCodeAccessTokenProviderTests method testGetAccessToken.
@Test
public void testGetAccessToken() throws Exception {
AccessTokenRequest request = new DefaultAccessTokenRequest();
request.setAuthorizationCode("foo");
request.setPreservedState(new Object());
resource.setAccessTokenUri("http://localhost/oauth/token");
assertEquals("FOO", provider.obtainAccessToken(resource, request).getValue());
}
use of org.springframework.security.oauth2.client.token.DefaultAccessTokenRequest in project spring-security-oauth by spring-projects.
the class AuthorizationCodeAccessTokenProviderTests method testGetAccessTokenRequest.
@Test
public void testGetAccessTokenRequest() throws Exception {
AccessTokenRequest request = new DefaultAccessTokenRequest();
request.setAuthorizationCode("foo");
request.setStateKey("bar");
request.setPreservedState(new Object());
resource.setAccessTokenUri("http://localhost/oauth/token");
resource.setPreEstablishedRedirectUri("http://anywhere.com");
assertEquals("FOO", provider.obtainAccessToken(resource, request).getValue());
// System.err.println(params);
assertEquals("authorization_code", params.getFirst("grant_type"));
assertEquals("foo", params.getFirst("code"));
assertEquals("http://anywhere.com", params.getFirst("redirect_uri"));
// State is not set in token request
assertEquals(null, params.getFirst("state"));
}
use of org.springframework.security.oauth2.client.token.DefaultAccessTokenRequest in project spring-security-oauth by spring-projects.
the class AuthorizationCodeAccessTokenProviderTests method testRedirectToAuthorizationEndpoint.
@Test
public void testRedirectToAuthorizationEndpoint() throws Exception {
AccessTokenRequest request = new DefaultAccessTokenRequest();
request.setCurrentUri("/come/back/soon");
resource.setUserAuthorizationUri("http://localhost/oauth/authorize");
try {
provider.obtainAccessToken(resource, request);
fail("Expected UserRedirectRequiredException");
} catch (UserRedirectRequiredException e) {
assertEquals("http://localhost/oauth/authorize", e.getRedirectUri());
assertEquals("/come/back/soon", e.getStateToPreserve());
}
}
use of org.springframework.security.oauth2.client.token.DefaultAccessTokenRequest in project spring-security-oauth by spring-projects.
the class AuthorizationCodeAccessTokenProviderWithConversionTests method testGetAccessTokenFromJson.
@Test
public void testGetAccessTokenFromJson() throws Exception {
final OAuth2AccessToken token = new DefaultOAuth2AccessToken("FOO");
requestFactory = new ClientHttpRequestFactory() {
public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException {
return new StubClientHttpRequest(new ObjectMapper().writeValueAsString(token));
}
};
AccessTokenRequest request = new DefaultAccessTokenRequest();
request.setAuthorizationCode("foo");
resource.setAccessTokenUri("http://localhost/oauth/token");
request.setPreservedState(new Object());
setUpRestTemplate();
assertEquals(token, provider.obtainAccessToken(resource, request));
}
Aggregations