コード例 #1
0
  /** {@inheritDoc} */
  public Token refreshAccessToken(Token accessToken) {
    String accessTokenEndpoint = api.getAccessTokenEndpoint();
    if (accessTokenEndpoint.contains("?grant_type=")) {
      // handle the ugly case where the grant_type parameter is already hardcoded in the constant
      // url
      accessTokenEndpoint = accessTokenEndpoint.substring(0, accessTokenEndpoint.indexOf("?"));
    }
    OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), accessTokenEndpoint);

    switch (api.getAccessTokenVerb()) {
      case POST:
        request.addBodyParameter(OAuthConstants.CLIENT_ID, config.getApiKey());
        request.addBodyParameter(OAuthConstants.CLIENT_SECRET, config.getApiSecret());
        // request.addBodyParameter(OAuthConstants.REDIRECT_URI, config.getCallback());
        request.addBodyParameter(OAuthConstants.GRANT_TYPE, api.getRefreshTokenParameterName());
        request.addBodyParameter(api.getRefreshTokenParameterName(), accessToken.getToken());
        break;
      case GET:
      default:
        request.addQuerystringParameter(OAuthConstants.CLIENT_ID, config.getApiKey());
        request.addQuerystringParameter(OAuthConstants.CLIENT_SECRET, config.getApiSecret());
        request.addQuerystringParameter(OAuthConstants.REDIRECT_URI, config.getCallback());
        request.addQuerystringParameter(
            OAuthConstants.GRANT_TYPE, api.getRefreshTokenParameterName());
        request.addQuerystringParameter(api.getRefreshTokenParameterName(), accessToken.getToken());
    }

    Response response = request.send();
    return api.getAccessTokenExtractor().extract(response.getBody());
  }
コード例 #2
0
 /** {@inheritDoc} */
 public Token getAccessToken(Token requestToken, Verifier verifier) {
   OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint());
   request.addQuerystringParameter(OAuthConstants.CLIENT_ID, config.getApiKey());
   request.addQuerystringParameter(OAuthConstants.CLIENT_SECRET, config.getApiSecret());
   request.addQuerystringParameter(OAuthConstants.CODE, verifier.getValue());
   request.addQuerystringParameter(OAuthConstants.REDIRECT_URI, config.getCallback());
   if (config.hasScope()) request.addQuerystringParameter(OAuthConstants.SCOPE, config.getScope());
   System.out.println("Access Token request is:" + request);
   Response response = request.send();
   System.out.println("Got the Access Token!");
   System.out.println("(if your curious here's the response: " + response.getBody() + " )");
   return api.getAccessTokenExtractor().extract(response.getBody());
 }
コード例 #3
0
  /** {@inheritDoc} */
  public Token refreshAccessToken(Token accessToken) {

    String accessTokenEndpoint = api.getAccessTokenEndpoint();
    if (accessTokenEndpoint.contains("?grant_type=")) {
      // handle the ugly case where the grant_type parameter is already hardcoded in the constant
      // url
      accessTokenEndpoint = accessTokenEndpoint.substring(0, accessTokenEndpoint.indexOf("?"));
    }
    OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), accessTokenEndpoint);
    request.addQuerystringParameter(OAuthConstants.CLIENT_ID, config.getApiKey());
    request.addQuerystringParameter(OAuthConstants.CLIENT_SECRET, config.getApiSecret());
    request.addQuerystringParameter(OAuthConstants.REDIRECT_URI, config.getCallback());
    request.addQuerystringParameter(OAuthConstants.GRANT_TYPE, api.getRefreshTokenParameterName());
    request.addQuerystringParameter(api.getRefreshTokenParameterName(), accessToken.getToken());
    Response response = request.send();
    System.out.println("Got the Refresh Token!");
    System.out.println("(if your curious here's the response: " + response.getBody() + " )");
    return api.getAccessTokenExtractor().extract(response.getBody());
  }
コード例 #4
0
 /** {@inheritDoc} */
 public Token getAccessToken(Token requestToken, Verifier verifier) {
   OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint());
   switch (api.getAccessTokenVerb()) {
     case POST:
       request.addBodyParameter(OAuthConstants.CLIENT_ID, config.getApiKey());
       request.addBodyParameter(OAuthConstants.CLIENT_SECRET, config.getApiSecret());
       request.addBodyParameter(OAuthConstants.CODE, verifier.getValue());
       request.addBodyParameter(OAuthConstants.REDIRECT_URI, config.getCallback());
       if (config.hasScope()) {
         request.addBodyParameter(OAuthConstants.SCOPE, config.getScope());
       }
       if (config.hasGrantType()) {
         request.addBodyParameter(OAuthConstants.GRANT_TYPE, config.getGrantType());
       }
       break;
     case GET:
     default:
       request.addQuerystringParameter(OAuthConstants.CLIENT_ID, config.getApiKey());
       request.addQuerystringParameter(OAuthConstants.CLIENT_SECRET, config.getApiSecret());
       request.addQuerystringParameter(OAuthConstants.CODE, verifier.getValue());
       request.addQuerystringParameter(OAuthConstants.REDIRECT_URI, config.getCallback());
       if (config.hasScope()) {
         request.addQuerystringParameter(OAuthConstants.SCOPE, config.getScope());
       }
       if (config.hasGrantType()) {
         request.addQuerystringParameter(OAuthConstants.GRANT_TYPE, config.getGrantType());
       }
   }
   Response response = request.send();
   return api.getAccessTokenExtractor().extract(response.getBody());
 }
コード例 #5
0
 /** {@inheritDoc} */
 public Token getAccessToken(Token requestToken, Verifier verifier) {
   OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint());
   request.addQuerystringParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.AUTHORIZATION_CODE);
   request.addQuerystringParameter(OAuthConstants.CLIENT_ID, config.getApiKey());
   request.addQuerystringParameter(OAuthConstants.CLIENT_SECRET, config.getApiSecret());
   request.addQuerystringParameter(OAuthConstants.CODE, verifier.getValue());
   request.addQuerystringParameter(OAuthConstants.REDIRECT_URI, config.getCallback());
   if (config.hasScope()) request.addQuerystringParameter(OAuthConstants.SCOPE, config.getScope());
   Response response = request.send();
   return api.getAccessTokenExtractor().extract(response.getBody());
 }
コード例 #6
0
  private void appendSignature(OAuthRequest request) {
    switch (config.getSignatureType()) {
      case Header:
        config.log("using Http Header signature");

        String oauthHeader = api.getHeaderExtractor().extract(request);
        request.addHeader(OAuthConstants.HEADER, oauthHeader);
        break;
      case QueryString:
        config.log("using Querystring signature");

        for (Map.Entry<String, String> entry : request.getOauthParameters().entrySet()) {
          request.addQuerystringParameter(entry.getKey(), entry.getValue());
        }
        break;
    }
  }
コード例 #7
0
 /** {@inheritDoc} */
 public void signRequest(Token accessToken, OAuthRequest request) {
   request.addQuerystringParameter(OAuthConstants.ACCESS_TOKEN, accessToken.getToken());
 }