Java Code Examples for org.springframework.social.oauth1.OAuth1Operations#fetchRequestToken()

The following examples show how to use org.springframework.social.oauth1.OAuth1Operations#fetchRequestToken() . 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 = "/twitterLogin")
public void printWelcome(HttpServletResponse response,HttpServletRequest request) {
 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);
    String authorizeUrl = oauth1Operations.buildAuthorizeUrl(requestToken.getValue(), OAuth1Parameters.NONE);
    try {
		response.sendRedirect(authorizeUrl);
	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}

      
   }
 
Example 2
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 3
Source File: OAuthController.java    From evernote-rest-webapp with Apache License 2.0 6 votes vote down vote up
@RequestMapping("/auth")
public Map<String, String> authorization(@RequestParam String callbackUrl,
                                         @RequestParam(required = false) boolean preferRegistration,
                                         @RequestParam(required = false) boolean supportLinkedSandbox) {

	// obtain request token (temporal credential)
	final OAuth1Operations oauthOperations = this.evernoteConnectionFactory.getOAuthOperations();
	final OAuthToken requestToken = oauthOperations.fetchRequestToken(callbackUrl, null); // no additional param

	// construct authorization url with callback url for client to redirect
	final OAuth1Parameters parameters = new OAuth1Parameters();
	if (preferRegistration) {
		parameters.set("preferRegistration", "true");  // create account
	}
	if (supportLinkedSandbox) {
		parameters.set("supportLinkedSandbox", "true");
	}
	final String authorizeUrl = oauthOperations.buildAuthorizeUrl(requestToken.getValue(), parameters);

	final Map<String, String> map = new HashMap<String, String>();
	map.put("authorizeUrl", authorizeUrl);
	map.put("requestTokenValue", requestToken.getValue());
	map.put("requestTokenSecret", requestToken.getSecret());
	return map;
}
 
Example 4
Source File: OAuth1CredentialProvider.java    From syndesis with Apache License 2.0 5 votes vote down vote up
@Override
public CredentialFlowState prepare(final String connectorId, final URI baseUrl, final URI returnUrl) {
    final OAuth1CredentialFlowState.Builder flowState = new OAuth1CredentialFlowState.Builder().returnUrl(returnUrl)
        .providerId(id);

    final OAuth1Operations oauthOperations = connectionFactory.getOAuthOperations();
    final OAuth1Parameters parameters = new OAuth1Parameters();

    final String stateKey = UUID.randomUUID().toString();
    flowState.key(stateKey);

    final OAuthToken oAuthToken;
    final OAuth1Version oAuthVersion = oauthOperations.getVersion();

    if (oAuthVersion == OAuth1Version.CORE_10) {
        parameters.setCallbackUrl(callbackUrlFor(baseUrl, EMPTY));

        oAuthToken = oauthOperations.fetchRequestToken(null, null);
    } else if (oAuthVersion == OAuth1Version.CORE_10_REVISION_A) {
        oAuthToken = oauthOperations.fetchRequestToken(callbackUrlFor(baseUrl, EMPTY), null);
    } else {
        throw new IllegalStateException("Unsupported OAuth 1 version: " + oAuthVersion);
    }
    flowState.token(oAuthToken);

    final String redirectUrl = oauthOperations.buildAuthorizeUrl(oAuthToken.getValue(), parameters);
    flowState.redirectUrl(redirectUrl);

    flowState.connectorId(connectorId);

    return flowState.build();
}