use of org.springframework.security.oauth2.client.token.AccessTokenRequest in project spring-security-oauth by spring-projects.
the class AuthorizationCodeAccessTokenProviderWithConversionTests method testGetErrorFromJson.
@Test
public void testGetErrorFromJson() throws Exception {
final InvalidClientException exception = new InvalidClientException("FOO");
requestFactory = new ClientHttpRequestFactory() {
public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException {
return new StubClientHttpRequest(HttpStatus.BAD_REQUEST, new ObjectMapper().writeValueAsString(exception));
}
};
AccessTokenRequest request = new DefaultAccessTokenRequest();
request.setAuthorizationCode("foo");
request.setPreservedState(new Object());
resource.setAccessTokenUri("http://localhost/oauth/token");
expected.expect(OAuth2AccessDeniedException.class);
expected.expect(hasCause(instanceOf(InvalidClientException.class)));
setUpRestTemplate();
provider.obtainAccessToken(resource, request);
}
use of org.springframework.security.oauth2.client.token.AccessTokenRequest in project spring-security-oauth by spring-projects.
the class AuthorizationCodeAccessTokenProviderWithConversionTests method testGetAccessTokenFromForm.
@Test
public void testGetAccessTokenFromForm() throws Exception {
final OAuth2AccessToken token = new DefaultOAuth2AccessToken("FOO");
final HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
requestFactory = new ClientHttpRequestFactory() {
public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException {
return new StubClientHttpRequest(responseHeaders, "access_token=FOO");
}
};
AccessTokenRequest request = new DefaultAccessTokenRequest();
request.setAuthorizationCode("foo");
request.setPreservedState(new Object());
resource.setAccessTokenUri("http://localhost/oauth/token");
setUpRestTemplate();
assertEquals(token, provider.obtainAccessToken(resource, request));
}
use of org.springframework.security.oauth2.client.token.AccessTokenRequest in project spring-security-oauth by spring-projects.
the class AuthorizationCodeAccessTokenProviderWithConversionTests method testGetErrorFromForm.
@Test
public void testGetErrorFromForm() throws Exception {
final HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
requestFactory = new ClientHttpRequestFactory() {
public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException {
return new StubClientHttpRequest(HttpStatus.BAD_REQUEST, responseHeaders, "error=invalid_client&error_description=FOO");
}
};
AccessTokenRequest request = new DefaultAccessTokenRequest();
request.setAuthorizationCode("foo");
request.setPreservedState(new Object());
resource.setAccessTokenUri("http://localhost/oauth/token");
expected.expect(OAuth2AccessDeniedException.class);
expected.expect(hasCause(instanceOf(InvalidClientException.class)));
setUpRestTemplate();
provider.obtainAccessToken(resource, request);
}
use of org.springframework.security.oauth2.client.token.AccessTokenRequest in project spring-security-oauth by spring-projects.
the class ImplicitAccessTokenProviderTests method testGetAccessTokenRequest.
@Test
public void testGetAccessTokenRequest() throws Exception {
AccessTokenRequest request = new DefaultAccessTokenRequest();
resource.setClientId("foo");
resource.setAccessTokenUri("http://localhost/oauth/authorize");
resource.setPreEstablishedRedirectUri("http://anywhere.com");
assertEquals("FOO", provider.obtainAccessToken(resource, request).getValue());
assertEquals("foo", params.getFirst("client_id"));
assertEquals("token", params.getFirst("response_type"));
assertEquals("http://anywhere.com", params.getFirst("redirect_uri"));
}
use of org.springframework.security.oauth2.client.token.AccessTokenRequest in project spring-security-oauth by spring-projects.
the class ResourceOwnerPasswordAccessTokenProviderTests method testCurrentUriNotUsed.
@Test
public void testCurrentUriNotUsed() throws Exception {
AccessTokenRequest request = new DefaultAccessTokenRequest();
request.set("username", "foo");
request.setCurrentUri("urn:foo:bar");
resource.setAccessTokenUri("http://localhost/oauth/token");
assertEquals("FOO", provider.obtainAccessToken(resource, request).getValue());
}
Aggregations