use of org.springframework.security.oauth2.client.token.DefaultAccessTokenRequest in project spring-security-oauth by spring-projects.
the class AuthorizationCodeAccessTokenProviderTests method testRedirectNotSpecified.
// A missing redirect just means the server has to deal with it
@Test(expected = UserRedirectRequiredException.class)
public void testRedirectNotSpecified() throws Exception {
AccessTokenRequest request = new DefaultAccessTokenRequest();
resource.setUserAuthorizationUri("http://localhost/oauth/authorize");
provider.obtainAccessToken(resource, request);
}
use of org.springframework.security.oauth2.client.token.DefaultAccessTokenRequest 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.DefaultAccessTokenRequest 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.DefaultAccessTokenRequest 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.DefaultAccessTokenRequest 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"));
}
Aggregations