Search in sources :

Example 1 with CoreOAuthConsumerSupport

use of org.springframework.security.oauth.consumer.client.CoreOAuthConsumerSupport in project spring-security-oauth by spring-projects.

the class GoogleOAuthTests method testGetRequestToken.

/**
 * tests getting a request token.
 */
@Test
public void testGetRequestToken() throws Exception {
    CoreOAuthConsumerSupport support = new CoreOAuthConsumerSupport();
    support.setStreamHandlerFactory(new DefaultOAuthURLStreamHandlerFactory());
    InMemoryProtectedResourceDetailsService service = new InMemoryProtectedResourceDetailsService();
    HashMap<String, ProtectedResourceDetails> detailsStore = new HashMap<String, ProtectedResourceDetails>();
    BaseProtectedResourceDetails googleDetails = new BaseProtectedResourceDetails();
    googleDetails.setRequestTokenURL("https://www.google.com/accounts/OAuthGetRequestToken");
    googleDetails.setAccessTokenURL("https://www.google.com/accounts/OAuthAuthorizeToken");
    googleDetails.setConsumerKey("anonymous");
    googleDetails.setSharedSecret(new SharedConsumerSecretImpl("anonymous"));
    googleDetails.setId("google");
    googleDetails.setUse10a(true);
    googleDetails.setSignatureMethod(HMAC_SHA1SignatureMethod.SIGNATURE_NAME);
    googleDetails.setRequestTokenHttpMethod("GET");
    HashMap<String, String> additional = new HashMap<String, String>();
    additional.put("scope", "http://picasaweb.google.com/data");
    googleDetails.setAdditionalParameters(additional);
    detailsStore.put(googleDetails.getId(), googleDetails);
    service.setResourceDetailsStore(detailsStore);
    support.setProtectedResourceDetailsService(service);
// uncomment to see a request to google.
// see http://code.google.com/apis/accounts/docs/OAuth_ref.html
// and http://jira.codehaus.org/browse/OAUTHSS-37
// OAuthConsumerToken token = support.getUnauthorizedRequestToken("google", "urn:mycallback");
// System.out.println(token.getValue());
// System.out.println(token.getSecret());
}
Also used : SharedConsumerSecretImpl(org.springframework.security.oauth.common.signature.SharedConsumerSecretImpl) DefaultOAuthURLStreamHandlerFactory(org.springframework.security.oauth.consumer.net.DefaultOAuthURLStreamHandlerFactory) HashMap(java.util.HashMap) CoreOAuthConsumerSupport(org.springframework.security.oauth.consumer.client.CoreOAuthConsumerSupport) Test(org.junit.Test)

Aggregations

HashMap (java.util.HashMap)1 Test (org.junit.Test)1 SharedConsumerSecretImpl (org.springframework.security.oauth.common.signature.SharedConsumerSecretImpl)1 CoreOAuthConsumerSupport (org.springframework.security.oauth.consumer.client.CoreOAuthConsumerSupport)1 DefaultOAuthURLStreamHandlerFactory (org.springframework.security.oauth.consumer.net.DefaultOAuthURLStreamHandlerFactory)1