Java Code Examples for org.scribe.model.Token#getToken()

The following examples show how to use org.scribe.model.Token#getToken() . 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: HubicOAuth20ServiceImpl.java    From swift-explorer with Apache License 2.0 6 votes vote down vote up
public Token refreshAccessToken (Token expiredToken)
{
	if (expiredToken == null)
		return null ;
	
	OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint());
	
	String authenticationCode = config.getApiKey() + ":" + config.getApiSecret() ;
	byte[] bytesEncodedAuthenticationCode = Base64.encodeBase64(authenticationCode.getBytes()); 
	request.addHeader ("Authorization", "Basic " + bytesEncodedAuthenticationCode) ;
	
	String charset = "UTF-8";
	
	request.setCharset(charset);
	request.setFollowRedirects(false);
	
	AccessToken at = new HubicTokenExtractorImpl ().getAccessToken(expiredToken.getRawResponse()) ;
	
	try
	{
		request.addBodyParameter("refresh_token", at.getRefreshToken());
		//request.addBodyParameter("refresh_token", URLEncoder.encode(at.getRefreshToken(), charset));
		request.addBodyParameter("grant_type", "refresh_token");
		request.addBodyParameter(OAuthConstants.CLIENT_ID, URLEncoder.encode(config.getApiKey(), charset));
		request.addBodyParameter(OAuthConstants.CLIENT_SECRET, URLEncoder.encode(config.getApiSecret(), charset));
	} 
	catch (UnsupportedEncodingException e) 
	{			
		logger.error("Error occurred while refreshing the access token", e);
	}
	
	Response response = request.send();
	Token newToken = api.getAccessTokenExtractor().extract(response.getBody());		
	// We need to keep the initial RowResponse because it contains the refresh token
	return new Token (newToken.getToken(), newToken.getSecret(), expiredToken.getRawResponse()) ;
}
 
Example 2
Source File: EvernoteAuthToken.java    From EverMemo with MIT License 5 votes vote down vote up
public EvernoteAuthToken(Token token) {
  super(token.getToken(), token.getSecret(), token.getRawResponse());
  this.mNoteStoreUrl = extract(getRawResponse(), NOTESTORE_REGEX);
  this.mWebApiUrlPrefix = extract(getRawResponse(), WEBAPI_REGEX);
  this.mUserId = Integer.parseInt(extract(getRawResponse(), USERID_REGEX));
}
 
Example 3
Source File: EvernoteOAuthActivity.java    From EverMemo with MIT License 5 votes vote down vote up
@Override
protected String doInBackground(Void... params) {
	String url = null;
	try {

		EvernoteSession session = EvernoteSession.getOpenSession();
		if (session != null) {
			// Network request
			BootstrapManager.BootstrapInfoWrapper infoWrapper = session
					.getBootstrapSession().getBootstrapInfo();

			if (infoWrapper != null) {
				BootstrapInfo info = infoWrapper.getBootstrapInfo();
				if (info != null) {
					mBootstrapProfiles = (ArrayList<BootstrapProfile>) info
							.getProfiles();
					if (mBootstrapProfiles != null
							&& mBootstrapProfiles.size() > 0
							&& mSelectedBootstrapProfilePos < mBootstrapProfiles
									.size()) {

						mSelectedBootstrapProfile = mBootstrapProfiles
								.get(mSelectedBootstrapProfilePos);
					}
				}
			}
		}

		if (mSelectedBootstrapProfile == null
				|| TextUtils.isEmpty(mSelectedBootstrapProfile
						.getSettings().getServiceHost())) {
			Log.d(LOGTAG, "Bootstrap did not return a valid host");
			return null;
		}

		OAuthService service = createService();

		Log.i(LOGTAG, "Retrieving OAuth request token...");
		Token reqToken = service.getRequestToken();
		mRequestToken = reqToken.getToken();
		mRequestTokenSecret = reqToken.getSecret();

		Log.i(LOGTAG, "Redirecting user for authorization...");
		url = service.getAuthorizationUrl(reqToken);
	} catch (BootstrapManager.ClientUnsupportedException cue) {

		return null;
	} catch (Exception ex) {
		Log.e(LOGTAG, "Failed to obtain OAuth request token", ex);
	}
	return url;
}
 
Example 4
Source File: EvernoteAuthToken.java    From EverMemo-EverNote with MIT License 5 votes vote down vote up
public EvernoteAuthToken(Token token) {
  super(token.getToken(), token.getSecret(), token.getRawResponse());
  this.mNoteStoreUrl = extract(getRawResponse(), NOTESTORE_REGEX);
  this.mWebApiUrlPrefix = extract(getRawResponse(), WEBAPI_REGEX);
  this.mUserId = Integer.parseInt(extract(getRawResponse(), USERID_REGEX));
}
 
Example 5
Source File: EvernoteOAuthActivity.java    From EverMemo-EverNote with MIT License 5 votes vote down vote up
@Override
protected String doInBackground(Void... params) {
  String url = null;
  try {

    EvernoteSession session = EvernoteSession.getOpenSession();
    if (session != null) {
      //Network request
      BootstrapManager.BootstrapInfoWrapper infoWrapper = session.getBootstrapSession().getBootstrapInfo();

      if (infoWrapper != null){
        BootstrapInfo info = infoWrapper.getBootstrapInfo();
        if(info != null) {
          mBootstrapProfiles = (ArrayList<BootstrapProfile>) info.getProfiles();
          if (mBootstrapProfiles != null &&
              mBootstrapProfiles.size() > 0 &&
              mSelectedBootstrapProfilePos < mBootstrapProfiles.size()){

            mSelectedBootstrapProfile = mBootstrapProfiles.get(mSelectedBootstrapProfilePos);
          }
        }
      }
    }

    if(mSelectedBootstrapProfile == null || TextUtils.isEmpty(mSelectedBootstrapProfile.getSettings().getServiceHost())) {
      Log.d(LOGTAG, "Bootstrap did not return a valid host");
      return null;
    }

    OAuthService service = createService();

    Log.i(LOGTAG, "Retrieving OAuth request token...");
    Token reqToken = service.getRequestToken();
    mRequestToken = reqToken.getToken();
    mRequestTokenSecret = reqToken.getSecret();

    Log.i(LOGTAG, "Redirecting user for authorization...");
    url = service.getAuthorizationUrl(reqToken);
  } catch(BootstrapManager.ClientUnsupportedException cue) {

    return null;
  } catch (Exception ex) {
    Log.e(LOGTAG, "Failed to obtain OAuth request token", ex);
  }
  return url;
}
 
Example 6
Source File: SmugMugOauthApi.java    From data-transfer-project with Apache License 2.0 4 votes vote down vote up
@Override
public String getAuthorizationUrl(Token requestToken) {
  return "https://secure.smugmug.com/services/oauth/1.0a/authorize?oauth_token="
      + requestToken.getToken();
}
 
Example 7
Source File: XeroOAuthService.java    From xero-java-client with Apache License 2.0 4 votes vote down vote up
@Override
public String getAuthorizationUrl(Token token) {
  return BASE_URL + "Authorize?oauth_token=" + token.getToken();
}