Example usage for org.springframework.security.oauth.consumer.client OAuthRestTemplate OAuthRestTemplate

List of usage examples for org.springframework.security.oauth.consumer.client OAuthRestTemplate OAuthRestTemplate

Introduction

In this page you can find the example usage for org.springframework.security.oauth.consumer.client OAuthRestTemplate OAuthRestTemplate.

Prototype

public OAuthRestTemplate(ProtectedResourceDetails resource) 

Source Link

Usage

From source file:ltistarter.oauth.OAuthUtils.java

public static ResponseEntity sendOAuth1Request(String url, String consumerKey, String sharedSecret,
        Map<String, String> params, Map<String, String> headers) {
    assert url != null;
    assert consumerKey != null;
    assert sharedSecret != null;
    BaseProtectedResourceDetails prd = new BaseProtectedResourceDetails();
    prd.setId("oauth");
    prd.setConsumerKey(consumerKey);/*w w  w  . j a va2s.c  o m*/
    prd.setSharedSecret(new SharedConsumerSecretImpl(sharedSecret));
    prd.setAdditionalParameters(params);
    prd.setAdditionalRequestHeaders(headers);
    OAuthRestTemplate restTemplate = new OAuthRestTemplate(prd);
    ResponseEntity<String> response = restTemplate.postForEntity(url, params, String.class,
            (Map<String, ?>) null);
    return response;
}

From source file:org.cloudfoundry.identity.uaa.social.OAuthClientAuthenticationFilterTests.java

@Test
public void testFacebookAuthentication() throws Exception {
    OAuthRestTemplate restTemplate = new OAuthRestTemplate(resource);
    setUpContext("twitter.token", "twitter.secret", "twitter.key", "twitter.shared");
    filter.setRestTemplate(restTemplate);
    filter.setUserInfoUrl("https://api.twitter.com/1/account/verify_credentials.json");
    filter.afterPropertiesSet();//from  w  ww . j  av a 2 s . co  m
    SocialClientUserDetails user = filter.getUserDetails();
    assertTrue(!user.getAuthorities().isEmpty());
}

From source file:org.awesomeagile.webapp.config.HackpadConfig.java

@Hackpad
@Bean//from   ww  w  .  ja v a 2  s. c om
public OAuthRestTemplate getHackpadRestTemplate() {
    BaseProtectedResourceDetails resource = new BaseProtectedResourceDetails();
    resource.setConsumerKey(hackpadClientId);
    resource.setSharedSecret(new SharedConsumerSecretImpl(hackpadClientSecret));
    resource.setAcceptsAuthorizationHeader(false);
    return new OAuthRestTemplate(resource);
}

From source file:org.cloudfoundry.identity.uaa.client.OAuthClientAuthenticationFilterTests.java

@Test
public void testTwitterAuthentication() throws Exception {
    OAuthRestTemplate restTemplate = new OAuthRestTemplate(resource);
    setUpContext("twitter.token", "twitter.secret", "twitter.key", "twitter.shared");
    filter.setRestTemplate(restTemplate);
    filter.setUserInfoUrl("https://api.twitter.com/1/account/verify_credentials.json");
    filter.afterPropertiesSet();/*w w  w.  jav  a 2  s. co m*/
    SocialClientUserDetails user = (SocialClientUserDetails) filter.getPrincipal();
    assertTrue(!user.getAuthorities().isEmpty());
}

From source file:org.cloudfoundry.identity.uaa.social.OAuthClientAuthenticationFilterTests.java

@Test
public void testLinkedInAuthentication() throws Exception {
    OAuthRestTemplate restTemplate = new OAuthRestTemplate(resource);
    setUpContext("linked.token", "linked.secret", "linked.key", "linked.shared");
    filter.setRestTemplate(restTemplate);
    filter.setUserInfoUrl(//from  ww  w  . j av a2 s  .c  om
            "http://api.linkedin.com/v1/people/~:(id,first-name,last-name,formatted-name,api-standard-profile-request,public-profile-url)?format=json");
    filter.afterPropertiesSet();
    SocialClientUserDetails user = filter.getUserDetails();
    assertTrue(!user.getAuthorities().isEmpty());
}

From source file:org.cloudfoundry.identity.uaa.client.OAuthClientAuthenticationFilterTests.java

@Test
public void testLinkedInAuthentication() throws Exception {
    OAuthRestTemplate restTemplate = new OAuthRestTemplate(resource);
    setUpContext("linked.token", "linked.secret", "linked.key", "linked.shared");
    filter.setRestTemplate(restTemplate);
    filter.setUserInfoUrl(//  w  w  w . j  a v a  2 s. co  m
            "http://api.linkedin.com/v1/people/~:(id,first-name,last-name,formatted-name,api-standard-profile-request,public-profile-url)?format=json");
    filter.afterPropertiesSet();
    SocialClientUserDetails user = (SocialClientUserDetails) filter.getPrincipal();
    assertTrue(!user.getAuthorities().isEmpty());
}