Package oauth.signpost

Examples of oauth.signpost.OAuthProvider


               
                // get the request token credentials
                Credentials request_credentials = Credentials.getCredentials(request, provider, Credentials.Type.REQUEST);

                OAuthConsumer consumer = OAuthUtilities.getConsumer(request_credentials, provider);
                OAuthProvider pp = provider.getProvider();
               
                if (request_credentials == null) {
                    // no credentials were found, so let's start the dance

                    // get the request token

                    String url = pp.retrieveRequestToken(consumer, callbackURL);
                   
                    request_credentials = new Credentials(consumer.getToken(), consumer.getTokenSecret(), provider);

                    // and set them to that we can retrieve them later in the second part of the dance
                    Credentials.setCredentials(request, response, request_credentials, Credentials.Type.REQUEST, 3600);
                   
                    // now redirect the user to the Authorize URL where she can authenticate against the
                    // service provider and authorize us.
                    // The provider will bounce the user back here for us to continue the dance.
                   
                    response.sendRedirect(url);
                } else {
                    // we are at the second stage of the dance, so we need need to obtain the access credentials now
                   
                    // if we got here, it means that the user performed a valid authentication against the
                    // service provider and authorized us, so now we can request more permanent credentials
                    // to the service provider and save those as well for later use.

                    // this is set only for OAuth 1.0a 
                    String verificationCode = request.getParameter(OAUTH_VERIFIER_PARAM);
                   
                    pp.retrieveAccessToken(consumer, verificationCode);

                    access_credentials = new Credentials(consumer.getToken(), consumer.getTokenSecret(), provider);

                    // no matter the result, we need to remove the request token
                    Credentials.deleteCredentials(request, response, provider, Credentials.Type.REQUEST);
View Full Code Here


            "http://twitter.com/oauth/authorize");
    }

    public String getAuthURL()
    {
        OAuthProvider provider = getDefaultProvider();
        OAuthConsumer consumer = getDefaultConsumer();

        String authURL = null;
        try
        {
            authURL = provider.retrieveRequestToken(consumer, OAuth.OUT_OF_BAND);
            pinToken = consumer.getToken();
            pinTokenSecret = consumer.getTokenSecret();
        } catch (OAuthException e)
        {
            // Auth exception
View Full Code Here

    }

    public void acquireAccessTokens(String pin)
        throws OAuthException
    {
        OAuthProvider provider = getDefaultProvider();
        OAuthConsumer consumer = getDefaultConsumer();

        consumer.setTokenWithSecret(pinToken, pinTokenSecret);

        pinToken = null;
        pinTokenSecret = null;

        provider.retrieveAccessToken(consumer, pin);

        setAccessToken(consumer.getToken());
        setTokenSecret(consumer.getTokenSecret());
        setScreenName(provider.getResponseParameters().get("screen_name").first());
    }
View Full Code Here

    System.setProperty("debug", "true");
   
    OAuthConsumer consumer = new CommonsHttpOAuthConsumer(consumerKey, consumerSecret);

    // Note: we have to add the consumer key in the authorization URL to make it work
    OAuthProvider provider = new CommonsHttpOAuthProvider(REQUEST_TOKEN_URL,
                               ACCESS_TOKEN_URL,
                              AUTHORIZATION_URL + "&client_id=" + consumerKey);
    /*
     *  This has to be done once to get request token
     */
    provider.setOAuth10a(true);
    // for some reason, SignPost does not append oauth_callback so I
    // added it directly into the AUTHORIZATION_URL
    String requestUrl = provider.retrieveRequestToken(consumer, CALLBACK_URL);
    System.out.println("Copy/Paste the following URL in your browser: " + requestUrl);
    System.out.print("Enter your token: ");
    // read authorization code
    Scanner scanner = new Scanner(System.in);
    String authorizationCode = scanner.nextLine().trim();

    provider.retrieveAccessToken(consumer, authorizationCode);
       
    String accessToken = consumer.getToken();
    String tokenSecret = consumer.getTokenSecret();
    System.out.println("Token: " + accessToken + ". Secret: " + tokenSecret);

View Full Code Here

    additionalParameter.put("api_key", apiKey);
    consumer.setAdditionalParameters(additionalParameter);

    HttpClient httpClient = env.getHttpClient();

    OAuthProvider provider = new CommonsHttpOAuthProvider(
        "https://api.bodymedia.com/oauth/request_token?api_key="+apiKey,
        "https://api.bodymedia.com/oauth/access_token?api_key="+apiKey,
        "https://api.bodymedia.com/oauth/authorize?api_key="+apiKey, httpClient);

    request.getSession().setAttribute(BODYMEDIA_OAUTH_CONSUMER, consumer);
    request.getSession().setAttribute(BODYMEDIA_OAUTH_PROVIDER, provider);

        String approvalPageUrl = null;
        try {
            approvalPageUrl = provider.retrieveRequestToken(consumer,
                    oauthCallback);
        } catch (Throwable t) {
            logger.error("Couldn't retrieve BodyMedia request token.");
            t.printStackTrace();
            notificationsService.addNamedNotification(AuthHelper.getGuestId(),
View Full Code Here

      OAuthNotAuthorizedException, OAuthExpectationFailedException,
      OAuthCommunicationException {

    OAuthConsumer consumer = (OAuthConsumer) request.getSession()
        .getAttribute(BODYMEDIA_OAUTH_CONSUMER);
    OAuthProvider provider = (OAuthProvider) request.getSession()
        .getAttribute(BODYMEDIA_OAUTH_PROVIDER);
    String verifier = request.getParameter("oauth_verifier");
    provider.retrieveAccessToken(consumer, verifier);
    Guest guest = AuthHelper.getGuest();

        ApiKey apiKey;
        if (request.getParameter("apiKeyId")!=null) {
            long apiKeyId = Long.valueOf(request.getParameter("apiKeyId"));
            apiKey = guestService.getApiKey(apiKeyId);
        } else
            apiKey = guestService.createApiKey(guest.getId(), connector());

        guestService.setApiKeyAttribute(apiKey, "api_key", env.get("bodymediaConsumerKey"));
    guestService.setApiKeyAttribute(apiKey,
        "accessToken", consumer.getToken());
    guestService.setApiKeyAttribute(apiKey,
        "tokenSecret", consumer.getTokenSecret());
        guestService.setApiKeyAttribute(apiKey,
                "tokenExpiration", provider.getResponseParameters().get("xoauth_token_expiration_time").first());

        // Store the OAuth server keys used for the token upgrade, which are the ones currently in oauth.properties
        // into ApiKeyAttributes.  The values in oauth.properties may change over time, so we need to preserve
        // the values used for the token creation with the ApiKey itself.
        guestService.setApiKeyAttribute(apiKey, "bodymediaConsumerKey", env.get("bodymediaConsumerKey"));
View Full Code Here

                                accessToken);
        consumer.setAdditionalParameters(additionalParameter);

        HttpClient httpClient = env.getHttpClient();

        OAuthProvider provider = new CommonsHttpOAuthProvider(
                "https://api.bodymedia.com/oauth/request_token?api_key="+bodymediaConsumerKey,
                "https://api.bodymedia.com/oauth/access_token?api_key="+bodymediaConsumerKey,
                "https://api.bodymedia.com/oauth/authorize?api_key="+bodymediaConsumerKey, httpClient);

        try {
            provider.retrieveAccessToken(consumer, null);

            guestService.setApiKeyAttribute(updateInfo.apiKey,
                                            "accessToken", consumer.getToken());
            guestService.setApiKeyAttribute(updateInfo.apiKey,
                                            "tokenSecret", consumer.getTokenSecret());
            guestService.setApiKeyAttribute(updateInfo.apiKey,
                                            "tokenExpiration", provider.getResponseParameters().get("xoauth_token_expiration_time").first());

            // Record this connector as having status up
            guestService.setApiKeyStatus(updateInfo.apiKey.getId(), ApiKey.Status.STATUS_UP, null, null);
            // Schedule an update for this connector
            connectorUpdateService.updateConnector(updateInfo.apiKey, false);
View Full Code Here

        OAuthConsumer consumer = new DefaultOAuthConsumer(
                userUrl,
                getConsumerSecret());
        consumer.setMessageSigner(new PlainTextMessageSigner());
               
        OAuthProvider provider = new DefaultOAuthProvider(
            "https://" + userUrl + ".freshbooks.com/oauth/oauth_request.php",
            "https://" + userUrl + ".freshbooks.com/oauth/oauth_access.php",
            "https://" + userUrl + ".freshbooks.com/oauth/oauth_authorize.php");
       
    request.getSession().setAttribute(FRESHBOOKS_OAUTH_CONSUMER, consumer);
    request.getSession().setAttribute(FRESHBOOKS_OAUTH_PROVIDER, provider);
    System.out.println("the token secret is: " + consumer.getTokenSecret());
   
    provider.setOAuth10a(true);
    String approvalPageUrl = provider.retrieveRequestToken(consumer, oauthCallback);
   
    return "redirect:" + approvalPageUrl;
  }
View Full Code Here

  @RequestMapping(value = "/upgradeToken")
  public String upgradeToken(HttpServletRequest request,
      HttpServletResponse response) throws OAuthException, OAuthMessageSignerException, OAuthNotAuthorizedException, OAuthExpectationFailedException, OAuthCommunicationException {
    OAuthConsumer consumer = (OAuthConsumer) request.getSession().getAttribute(FRESHBOOKS_OAUTH_CONSUMER);
    OAuthProvider provider = (OAuthProvider) request.getSession().getAttribute(FRESHBOOKS_OAUTH_PROVIDER);
    String verifier = request.getParameter("oauth_verifier");
    provider.retrieveAccessToken(consumer, verifier);
    Guest guest = AuthHelper.getGuest();

        final Connector connector = Connector.getConnector("freshbooks");
        final ApiKey apiKey = guestService.createApiKey(guest.getId(), connector);
View Full Code Here

   
    OAuthConsumer consumer = new DefaultOAuthConsumer(
                consumerKey,
                consumerSecret);
       
        OAuthProvider provider = new DefaultOAuthProvider(
            "https://api.linkedin.com/uas/oauth/requestToken",
            "https://api.linkedin.com/uas/oauth/accessToken",
            "https://api.linkedin.com/uas/oauth/authorize");
       
    request.getSession().setAttribute(LINKEDIN_OAUTH_CONSUMER, consumer);
    request.getSession().setAttribute(LINKEDIN_OAUTH_PROVIDER, provider);
    System.out.println("the token secret is: " + consumer.getTokenSecret());
   
    String approvalPageUrl = provider.retrieveRequestToken(consumer, oauthCallback);
   
    return "redirect:" + approvalPageUrl;
  }
View Full Code Here

TOP

Related Classes of oauth.signpost.OAuthProvider

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.