org.springframework.social.oauth1.AuthorizedRequestToken Java Examples

The following examples show how to use org.springframework.social.oauth1.AuthorizedRequestToken. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SocialLogin.java    From Spring-MVC-Blueprints with MIT License 6 votes vote down vote up
@RequestMapping(value = "/twitterAuthentication")
 public RedirectView callback(@RequestParam(value = "oauth_token") String oauthToken, @RequestParam(value = "oauth_verifier") String oauthVerifier) {
TwitterConnectionFactory connectionFactoryTwitter = 
		 new TwitterConnectionFactory("<consumer id>","<consumer key>");
OAuth1Operations oauth1Operations = connectionFactoryTwitter.getOAuthOperations();
OAuthToken  requestToken = oauth1Operations.fetchRequestToken("http://www.localhost:8080/ch08/erp/twitterAuthentication.html", null);
RedirectView redirectView = new RedirectView();
redirectView.setContextRelative(true);
   OAuthToken accessToken = oauth1Operations.exchangeForAccessToken(new AuthorizedRequestToken(requestToken, oauthVerifier), OAuth1Parameters.NONE);
   
   if(accessToken.equals("<enter access token here>")){
   	redirectView.setUrl("/erp/paymentmodes.xml");
   }else{
   	redirectView.setUrl("http://www.google.com");
   }
   return redirectView;
 }
 
Example #2
Source File: OAuth1CredentialProvider.java    From syndesis with Apache License 2.0 5 votes vote down vote up
@Override
public CredentialFlowState finish(final CredentialFlowState givenFlowState, final URI baseUrl) {
    final OAuth1CredentialFlowState flowState = flowState(givenFlowState);

    final AuthorizedRequestToken requestToken = new AuthorizedRequestToken(flowState.getToken(),
        flowState.getVerifier());

    final OAuthToken accessToken = connectionFactory.getOAuthOperations().exchangeForAccessToken(requestToken,
        null);

    return new OAuth1CredentialFlowState.Builder().createFrom(flowState).accessToken(accessToken).build();
}
 
Example #3
Source File: CredentialsTest.java    From syndesis with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldFinishOAuth1Acquisition() {
    final OAuthToken token = new OAuthToken("value", "secret");

    final OAuth1ConnectionFactory<?> oauth1 = mock(OAuth1ConnectionFactory.class);
    final OAuth1Applicator applicator = new OAuth1Applicator(properties);
    when(locator.providerWithId("providerId"))
        .thenReturn(new OAuth1CredentialProvider<>("providerId", oauth1, applicator));

    final OAuth1Operations operations = mock(OAuth1Operations.class);
    when(oauth1.getOAuthOperations()).thenReturn(operations);

    final ArgumentCaptor<AuthorizedRequestToken> requestToken = ArgumentCaptor
        .forClass(AuthorizedRequestToken.class);
    final OAuthToken accessToken = new OAuthToken("tokenValue", "tokenSecret");
    @SuppressWarnings({"unchecked", "rawtypes"})
    final Class<MultiValueMap<String, String>> multimapType = (Class) MultiValueMap.class;
    when(operations.exchangeForAccessToken(requestToken.capture(), isNull(multimapType))).thenReturn(accessToken);

    applicator.setAccessTokenSecretProperty("accessTokenSecretProperty");
    applicator.setAccessTokenValueProperty("accessTokenValueProperty");
    applicator.setConsumerKeyProperty("consumerKeyProperty");
    applicator.setConsumerSecretProperty("consumerSecretProperty");

    final CredentialFlowState flowState = new OAuth1CredentialFlowState.Builder().providerId("providerId")
        .token(token).returnUrl(URI.create("/ui#state")).verifier("verifier").build();

    final CredentialFlowState finalFlowState = credentials.finishAcquisition(flowState,
        URI.create("https://www.example.com"));

    final AuthorizedRequestToken capturedRequestToken = requestToken.getValue();
    assertThat(capturedRequestToken.getValue()).isEqualTo("value");
    assertThat(capturedRequestToken.getSecret()).isEqualTo("secret");
    assertThat(capturedRequestToken.getVerifier()).isEqualTo("verifier");

    assertThat(finalFlowState)
        .isEqualTo(new OAuth1CredentialFlowState.Builder().createFrom(flowState).accessToken(accessToken).build());
}
 
Example #4
Source File: OAuthController.java    From evernote-rest-webapp with Apache License 2.0 5 votes vote down vote up
@RequestMapping("/accessToken")
public EvernoteOAuthToken obtainAccessToken(@RequestParam String oauthToken, @RequestParam String oauthVerifier,
                                            @RequestParam String requestTokenSecret) {
	final OAuthToken requestToken = new OAuthToken(oauthToken, requestTokenSecret);
	final AuthorizedRequestToken authorizedRequestToken = new AuthorizedRequestToken(requestToken, oauthVerifier);

	final OAuth1Operations oAuth1Operations = this.evernoteConnectionFactory.getOAuthOperations();  // EvernoteOAuth1Operations
	final OAuthToken accessToken = oAuth1Operations.exchangeForAccessToken(authorizedRequestToken, null);  // no additional param
	return (EvernoteOAuthToken) accessToken;
}