Package oauth.signpost

Examples of oauth.signpost.OAuthConsumer


  }

  @Override
  public void updateConnectorData(UpdateInfo updateInfo) throws Exception {
        initChannelMapping(updateInfo);
        final OAuthConsumer consumer = setupConsumer(updateInfo.apiKey);
    List<ObjectType> objectTypes = updateInfo.objectTypes();
    if (objectTypes.contains(ObjectType.getObjectType(connector(), "tweet"))) {
      refreshStatuses(updateInfo, consumer);
    } else if (objectTypes.contains(ObjectType.getObjectType(connector(), "mention"))) {
      refreshMentions(updateInfo, consumer);
View Full Code Here


      oauthCallback += "?guestId=" + request.getParameter("guestId");

        String consumerKey = getConsumerKey();
    String consumerSecret = getConsumerSecret();
   
    OAuthConsumer consumer = new CommonsHttpOAuthConsumer(
                consumerKey,
                consumerSecret);
       
        OAuthProvider provider = new CommonsHttpOAuthProvider(
            "http://www.khanacademy.org/api/auth/request_token",
            "http://www.khanacademy.org/api/auth/access_token",
            "http://www.khanacademy.org/api/auth/authorize");
       
    request.getSession().setAttribute(KHAN_OAUTH_CONSUMER, consumer);
    request.getSession().setAttribute(KHAN_OAUTH_PROVIDER, provider);

    try {
      provider.retrieveRequestToken(consumer, oauthCallback);
    } catch (Throwable e) {
      //TODO: a redirection happens here, and it should be handled
      System.out.println("redirection here");
    }
    System.out.println("the token secret is (musn't be null): " + consumer.getTokenSecret());
   
    return "redirect:" + "/home";
  }
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(KHAN_OAUTH_CONSUMER);
    OAuthProvider provider = (OAuthProvider) request.getSession().getAttribute(KHAN_OAUTH_PROVIDER);
    String verifier = request.getParameter("oauth_verifier");
    provider.retrieveAccessToken(consumer, verifier);
    Guest guest = AuthHelper.getGuest();

        final Connector connector = Connector.getConnector("khanacademy");
        final ApiKey apiKey = guestService.createApiKey(guest.getId(), connector);

    guestService.setApiKeyAttribute(apiKey, "accessToken", consumer.getToken());
    guestService.setApiKeyAttribute(apiKey, "tokenSecret", consumer.getTokenSecret());

    return "redirect:/app/from/"+connector.getName();
  }
View Full Code Here

    String oauthCallback = ControllerSupport.getLocationBase(request, env)
    + "twitter/upgradeToken";
    if (request.getParameter("guestId")!=null)
      oauthCallback += "?guestId=" + request.getParameter("guestId");

        OAuthConsumer consumer = new DefaultOAuthConsumer(
                getConsumerKey(),
                getConsumerSecret());
       
        HttpClient httpClient = env.getHttpClient();
       
        OAuthProvider provider = new CommonsHttpOAuthProvider(
            "https://api.twitter.com/oauth/request_token",
            "https://api.twitter.com/oauth/access_token",
            "https://api.twitter.com/oauth/authorize",
            httpClient);
       
    request.getSession().setAttribute(TWITTER_OAUTH_CONSUMER, consumer);
    request.getSession().setAttribute(TWITTER_OAUTH_PROVIDER, provider);
    System.out.println("the token secret is: " + consumer.getTokenSecret());
        if (request.getParameter("apiKeyId") != null)
            oauthCallback += "?apiKeyId=" + request.getParameter("apiKeyId");

    String approvalPageUrl = provider.retrieveRequestToken(consumer, oauthCallback);
   
View Full Code Here

    return "redirect:" + approvalPageUrl;
  }

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

        final Connector connector = Connector.getConnector("twitter");
        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.populateApiKey(apiKey.getId());
    guestService.setApiKeyAttribute(apiKey,  "accessToken", consumer.getToken());
    guestService.setApiKeyAttribute(apiKey,  "tokenSecret", consumer.getTokenSecret());

        if (request.getParameter("apiKeyId")!=null)
            return "redirect:/app/tokenRenewed/" + connector.getName();
        else
        return "redirect:/app/from/"+connector.getName();
View Full Code Here

      oauthCallback += "?guestId=" + request.getParameter("guestId");

    String consumerKey = env.get("fitbitConsumerKey");
    String consumerSecret = env.get("fitbitConsumerSecret");

    OAuthConsumer consumer = new DefaultOAuthConsumer(consumerKey,
        consumerSecret);

    OAuthProvider provider = new DefaultOAuthProvider(
        "https://api.fitbit.com/oauth/request_token",
        "https://api.fitbit.com/oauth/access_token",
View Full Code Here

    return "redirect:" + approvalPageUrl;
  }

  @RequestMapping(value = "/upgradeToken")
  public String upgradeToken(HttpServletRequest request) throws Exception {
    OAuthConsumer consumer = (OAuthConsumer) request.getSession()
        .getAttribute(FITBIT_OAUTH_CONSUMER);
    OAuthProvider provider = (OAuthProvider) request.getSession()
        .getAttribute(FITBIT_OAUTH_PROVIDER);
    String verifier = request.getParameter("oauth_verifier");
    provider.retrieveAccessToken(consumer, verifier);
    Guest guest = AuthHelper.getGuest();

        ApiKey apiKey;
        if (request.getSession().getAttribute(FITBIT_RENEWTOKEN_APIKEYID)!=null) {
            final String apiKeyIdString = (String) request.getSession().getAttribute(FITBIT_RENEWTOKEN_APIKEYID);
            long apiKeyId = Long.valueOf(apiKeyIdString);
            apiKey = guestService.getApiKey(apiKeyId);
        } else
            apiKey = guestService.createApiKey(guest.getId(), connector());

        guestService.populateApiKey(apiKey.getId());
    guestService.setApiKeyAttribute(apiKey,
        "accessToken", consumer.getToken());
    guestService.setApiKeyAttribute(apiKey,
        "tokenSecret", consumer.getTokenSecret());

        if (request.getSession().getAttribute(FITBIT_RENEWTOKEN_APIKEYID)!=null) {
            request.getSession().removeAttribute(FITBIT_RENEWTOKEN_APIKEYID);
            return "redirect:/app/tokenRenewed/" + connector().getName();
        }
View Full Code Here

            URL url = new URL(urlString);
            HttpURLConnection request = (HttpURLConnection) url.openConnection();
            if (method!=null && method.length>0)
                request.setRequestMethod(method[0]);

            OAuthConsumer consumer = new DefaultOAuthConsumer(
                    getConsumerKey(updateInfo.apiKey), getConsumerSecret(updateInfo.apiKey));

            consumer.setTokenWithSecret(
                    guestService.getApiKeyAttribute(updateInfo.apiKey,"accessToken"),
                    guestService.getApiKeyAttribute(updateInfo.apiKey,"tokenSecret"));

            // sign the request (consumer is a Signpost DefaultOAuthConsumer)
            try {
                consumer.sign(request);
            } catch (Exception e) {
                throw new RuntimeException("OAuth exception: " + e.getMessage());
            }
            request.connect();
            final int httpResponseCode = request.getResponseCode();
View Full Code Here

            oauthCallback += "?guestId=" + request.getParameter("guestId");

        String consumerKey = env.get("withingsConsumerKey");
        String consumerSecret = env.get("withingsConsumerSecret");

        OAuthConsumer consumer = new DefaultOAuthConsumer(consumerKey,
                                                          consumerSecret);

        OAuthProvider provider = new DefaultOAuthProvider(
                "https://oauth.withings.com/account/request_token",
                "https://oauth.withings.com/account/access_token",
View Full Code Here

        return "redirect:" + approvalPageUrl;
    }

    @RequestMapping(value = "/upgradeToken")
    public String upgradeToken(HttpServletRequest request) throws Exception {
        OAuthConsumer consumer = (OAuthConsumer) request.getSession()
                .getAttribute(WITHINGS_OAUTH_CONSUMER);

        HttpParameters additionalParameter = new HttpParameters();
        String userid = request.getParameter("userid");
        additionalParameter.put("userid", userid);
        consumer.setAdditionalParameters(additionalParameter);

        OAuthProvider provider = (OAuthProvider) request.getSession()
                .getAttribute(WITHINGS_OAUTH_PROVIDER);
        String verifier = request.getParameter("oauth_verifier");
        provider.retrieveAccessToken(consumer, verifier);

        Guest guest = AuthHelper.getGuest();

        Connector connector = Connector.getConnector("withings");

        ApiKey apiKey;
        if (request.getSession().getAttribute(WITHINGS_RENEWTOKEN_APIKEYID)!=null) {
            final String apiKeyIdString = (String) request.getSession().getAttribute(WITHINGS_RENEWTOKEN_APIKEYID);
            long apiKeyId = Long.valueOf(apiKeyIdString);
            apiKey = guestService.getApiKey(apiKeyId);
        } else {
            apiKey = guestService.createApiKey(guest.getId(), connector);
        }

        // We need to store the consumer ID and secret with the
        // apiKeyAttributes in either the case of original creation of the key
        // or token renewal.  createApiKey actually handles the former case, but
        // not the latter.  Do it in all cases here.
        guestService.setApiKeyAttribute(apiKey, "withingsConsumerKey",
                                        env.get("withingsConsumerKey"));
        guestService.setApiKeyAttribute(apiKey, "withingsConsumerSecret",
                                        env.get("withingsConsumerSecret"));

        guestService.setApiKeyAttribute(apiKey,
                                        "accessToken", consumer.getToken());
        guestService.setApiKeyAttribute(apiKey,
                                        "tokenSecret", consumer.getTokenSecret());
        guestService.setApiKeyAttribute(apiKey,
                                        "userid", userid);
        guestService.setApiKeyAttribute(apiKey,
                                        HAS_UPGRADED_TO_OAUTH, "y");
View Full Code Here

TOP

Related Classes of oauth.signpost.OAuthConsumer

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.