use of org.springframework.security.oauth2.common.OAuth2AccessToken in project spring-security-oauth by spring-projects.
the class OAuth2RestTemplateTests method testAppendQueryParameterWithNoExistingParameters.
/**
* tests appendQueryParameter
*/
@Test
public void testAppendQueryParameterWithNoExistingParameters() throws Exception {
OAuth2AccessToken token = new DefaultOAuth2AccessToken("12345");
URI appended = restTemplate.appendQueryParameter(URI.create("https://graph.facebook.com/search"), token);
assertEquals("https://graph.facebook.com/search?bearer_token=12345", appended.toString());
}
use of org.springframework.security.oauth2.common.OAuth2AccessToken in project spring-security-oauth by spring-projects.
the class OAuth2RestTemplateTests method testDoubleEncodingOfParameterValue.
/**
* tests encoding of access token value
*/
@Test
public void testDoubleEncodingOfParameterValue() throws Exception {
OAuth2AccessToken token = new DefaultOAuth2AccessToken("1/qIxxx");
URI appended = restTemplate.appendQueryParameter(URI.create("https://graph.facebook.com/search"), token);
assertEquals("https://graph.facebook.com/search?bearer_token=1%2FqIxxx", appended.toString());
}
use of org.springframework.security.oauth2.common.OAuth2AccessToken in project spring-security-oauth by spring-projects.
the class OAuth2RestTemplateTests method testFragmentUri.
/**
* tests URI with fragment value
*/
@Test
public void testFragmentUri() throws Exception {
OAuth2AccessToken token = new DefaultOAuth2AccessToken("1234");
URI appended = restTemplate.appendQueryParameter(URI.create("https://graph.facebook.com/search#foo"), token);
assertEquals("https://graph.facebook.com/search?bearer_token=1234#foo", appended.toString());
}
use of org.springframework.security.oauth2.common.OAuth2AccessToken in project spring-security-oauth by spring-projects.
the class OAuth2RestTemplateTests method testTokenIsResetIfInvalid.
@Test
public void testTokenIsResetIfInvalid() throws Exception {
DefaultOAuth2AccessToken token = new DefaultOAuth2AccessToken("TEST");
token.setExpiration(new Date(System.currentTimeMillis() - 1000));
restTemplate.getOAuth2ClientContext().setAccessToken(token);
restTemplate.setAccessTokenProvider(new StubAccessTokenProvider() {
@Override
public OAuth2AccessToken obtainAccessToken(OAuth2ProtectedResourceDetails details, AccessTokenRequest parameters) throws UserRedirectRequiredException, AccessDeniedException {
throw new UserRedirectRequiredException("http://foo.com", Collections.<String, String>emptyMap());
}
});
try {
OAuth2AccessToken newToken = restTemplate.getAccessToken();
assertNotNull(newToken);
fail("Expected UserRedirectRequiredException");
} catch (UserRedirectRequiredException e) {
// planned
}
// context token should be reset as it clearly is invalid at this point
assertNull(restTemplate.getOAuth2ClientContext().getAccessToken());
}
use of org.springframework.security.oauth2.common.OAuth2AccessToken in project spring-security-oauth by spring-projects.
the class OAuth2RestTemplateTests method testNonEncodingOfUriTemplate.
/**
* tests no double encoding of existing query parameter
*/
@Test
public void testNonEncodingOfUriTemplate() throws Exception {
OAuth2AccessToken token = new DefaultOAuth2AccessToken("12345");
UriTemplate uriTemplate = new UriTemplate("https://graph.facebook.com/fql?q={q}");
URI expanded = uriTemplate.expand("[q: fql]");
URI appended = restTemplate.appendQueryParameter(expanded, token);
assertEquals("https://graph.facebook.com/fql?q=%5Bq:%20fql%5D&bearer_token=12345", appended.toString());
}
Aggregations