Package oauth.signpost.http

Examples of oauth.signpost.http.HttpParameters


  public TokenHolder postToken(String relativeUrl, TokenHolder tokenHolder, HttpParameters oauthParams,
    List<? extends NameValuePair> parameters) {
    byte[] response = post(relativeUrl, tokenHolder, oauthParams, parameters);
    try {
      HttpParameters responseParams = OAuth.decodeForm(new ByteArrayInputStream(response));
      String token = responseParams.getFirst(OAuth.OAUTH_TOKEN);
      String tokenSecret = responseParams.getFirst(OAuth.OAUTH_TOKEN_SECRET);
      tokenHolder.setToken(token, tokenSecret);
      return tokenHolder;
    } catch (IOException e) {
      throw new IllegalArgumentException("Failed to load OAuth token from response", e);
    }
View Full Code Here


   *            access token
   * @return an exception to throw for the given content
   */
  private BellaDatiRuntimeException buildException(int code, byte[] content, boolean hasToken) {
    try {
      HttpParameters oauthParams = OAuth.decodeForm(new ByteArrayInputStream(content));
      if (oauthParams.containsKey("oauth_problem")) {
        String problem = oauthParams.getFirst("oauth_problem");
        if ("missing_consumer".equals(problem) || "invalid_consumer".equals(problem)) {
          return new AuthorizationException(Reason.CONSUMER_KEY_UNKNOWN);
        } else if ("invalid_signature".equals(problem) || "signature_invalid".equals(problem)) {
          return new AuthorizationException(hasToken ? Reason.TOKEN_INVALID : Reason.CONSUMER_SECRET_INVALID);
        } else if ("domain_expired".equals(problem)) {
          return new AuthorizationException(Reason.DOMAIN_EXPIRED);
        } else if ("missing_token".equals(problem) || "invalid_token".equals(problem)) {
          return new AuthorizationException(Reason.TOKEN_INVALID);
        } else if ("unauthorized_token".equals(problem)) {
          return new AuthorizationException(Reason.TOKEN_UNAUTHORIZED);
        } else if ("token_expired".equals(problem)) {
          return new AuthorizationException(Reason.TOKEN_EXPIRED);
        } else if ("x_auth_disabled".equals(problem)) {
          return new AuthorizationException(Reason.X_AUTH_DISABLED);
        } else if ("piccolo_not_enabled".equals(problem)) {
          return new AuthorizationException(Reason.BD_MOBILE_DISABLED);
        } else if ("missing_username".equals(problem) || "missing_password".equals(problem)
          || "invalid_credentials".equals(problem) || "permission_denied".equals(problem)) {
          return new AuthorizationException(Reason.USER_CREDENTIALS_INVALID);
        } else if ("account_locked".equals(problem) || "user_not_active".equals(problem)) {
          return new AuthorizationException(Reason.USER_ACCOUNT_LOCKED);
        } else if ("domain_restricted".equals(problem)) {
          return new AuthorizationException(Reason.USER_DOMAIN_MISMATCH);
        } else if ("timestamp_refused".equals(problem)) {
          String acceptable = oauthParams.getFirst("oauth_acceptable_timestamps");
          if (acceptable != null && acceptable.contains("-")) {
            return new InvalidTimestampException(Long.parseLong(acceptable.split("-")[0]), Long.parseLong(acceptable
              .split("-")[1]));
          }
        }
View Full Code Here

        if (realm != null) {
            sb.append("realm=\"" + realm + "\", ");
        }

        // add all (x_)oauth parameters
        HttpParameters oauthParams = requestParameters.getOAuthParameters();
        oauthParams.put(OAuth.OAUTH_SIGNATURE, signature, true);

        Iterator<String> iter = oauthParams.keySet().iterator();
        while (iter.hasNext()) {
            String key = iter.next();
            sb.append(oauthParams.getAsHeaderElement(key));
            if (iter.hasNext()) {
                sb.append(", ");
            }
        }
View Full Code Here

    public static void deleteCredentials(HttpServletRequest request, HttpServletResponse response, Provider provider, Type type) {
        CookiesUtilities.deleteCookie(request, response, type.getCookieName(provider));
    }

    public static Credentials makeCredentials(String str, Provider provider) {
        HttpParameters p = OAuth.decodeForm(str);
        return new Credentials(p.getFirst(TOKEN), p.getFirst(SECRET), provider);
    }
View Full Code Here

        String apiKey = env.get("bodymediaConsumerKey");
    OAuthConsumer consumer = new DefaultOAuthConsumer(
        apiKey,
        env.get("bodymediaConsumerSecret"));
    HttpParameters additionalParameter = new HttpParameters();
    additionalParameter.put("api_key", apiKey);
    consumer.setAdditionalParameters(additionalParameter);

    HttpClient httpClient = env.getHttpClient();

    OAuthProvider provider = new CommonsHttpOAuthProvider(
View Full Code Here

                bodymediaConsumerSecret);

        String accessToken = guestService.getApiKeyAttribute(updateInfo.apiKey, "accessToken");
        consumer.setTokenWithSecret(accessToken,
                guestService.getApiKeyAttribute(updateInfo.apiKey, "tokenSecret"));
        HttpParameters additionalParameter = new HttpParameters();
        additionalParameter.put("api_key", bodymediaConsumerKey);
        additionalParameter.put("oauth_token",
                                accessToken);
        consumer.setAdditionalParameters(additionalParameter);

        HttpClient httpClient = env.getHttpClient();
View Full Code Here

    @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");
View Full Code Here

  public TokenHolder postToken(String relativeUrl, TokenHolder tokenHolder, HttpParameters oauthParams,
    List<? extends NameValuePair> parameters) {
    byte[] response = post(relativeUrl, tokenHolder, oauthParams, parameters);
    try {
      HttpParameters responseParams = OAuth.decodeForm(new ByteArrayInputStream(response));
      String token = responseParams.getFirst(OAuth.OAUTH_TOKEN);
      String tokenSecret = responseParams.getFirst(OAuth.OAUTH_TOKEN_SECRET);
      tokenHolder.setToken(token, tokenSecret);
      return tokenHolder;
    } catch (IOException e) {
      throw new IllegalArgumentException("Failed to load OAuth token from response", e);
    }
View Full Code Here

   *            access token
   * @return an exception to throw for the given content
   */
  private BellaDatiRuntimeException buildException(int code, byte[] content, boolean hasToken) {
    try {
      HttpParameters oauthParams = OAuth.decodeForm(new ByteArrayInputStream(content));
      if (oauthParams.containsKey("oauth_problem")) {
        String problem = oauthParams.getFirst("oauth_problem");
        if ("missing_consumer".equals(problem) || "invalid_consumer".equals(problem)) {
          return new AuthorizationException(Reason.CONSUMER_KEY_UNKNOWN);
        } else if ("invalid_signature".equals(problem) || "signature_invalid".equals(problem)) {
          return new AuthorizationException(hasToken ? Reason.TOKEN_INVALID : Reason.CONSUMER_SECRET_INVALID);
        } else if ("domain_expired".equals(problem)) {
          return new AuthorizationException(Reason.DOMAIN_EXPIRED);
        } else if ("missing_token".equals(problem) || "invalid_token".equals(problem)) {
          return new AuthorizationException(Reason.TOKEN_INVALID);
        } else if ("unauthorized_token".equals(problem)) {
          return new AuthorizationException(Reason.TOKEN_UNAUTHORIZED);
        } else if ("token_expired".equals(problem)) {
          return new AuthorizationException(Reason.TOKEN_EXPIRED);
        } else if ("x_auth_disabled".equals(problem)) {
          return new AuthorizationException(Reason.X_AUTH_DISABLED);
        } else if ("piccolo_not_enabled".equals(problem)) {
          return new AuthorizationException(Reason.BD_MOBILE_DISABLED);
        } else if ("missing_username".equals(problem) || "missing_password".equals(problem)
          || "invalid_credentials".equals(problem) || "permission_denied".equals(problem)) {
          return new AuthorizationException(Reason.USER_CREDENTIALS_INVALID);
        } else if ("account_locked".equals(problem) || "user_not_active".equals(problem)) {
          return new AuthorizationException(Reason.USER_ACCOUNT_LOCKED);
        } else if ("domain_restricted".equals(problem)) {
          return new AuthorizationException(Reason.USER_DOMAIN_MISMATCH);
        } else if ("timestamp_refused".equals(problem)) {
          String acceptable = oauthParams.getFirst("oauth_acceptable_timestamps");
          if (acceptable != null && acceptable.contains("-")) {
            return new InvalidTimestampException(Long.parseLong(acceptable.split("-")[0]), Long.parseLong(acceptable
              .split("-")[1]));
          }
        }
View Full Code Here

  public TokenHolder postToken(String relativeUrl, TokenHolder tokenHolder, HttpParameters oauthParams,
    List<? extends NameValuePair> parameters) {
    byte[] response = post(relativeUrl, tokenHolder, oauthParams, parameters);
    try {
      HttpParameters responseParams = OAuth.decodeForm(new ByteArrayInputStream(response));
      String token = responseParams.getFirst(OAuth.OAUTH_TOKEN);
      String tokenSecret = responseParams.getFirst(OAuth.OAUTH_TOKEN_SECRET);
      tokenHolder.setToken(token, tokenSecret);
      return tokenHolder;
    } catch (IOException e) {
      throw new IllegalArgumentException("Failed to load OAuth token from response", e);
    }
View Full Code Here

TOP

Related Classes of oauth.signpost.http.HttpParameters

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.