List of usage examples for com.google.api.client.googleapis.auth.oauth2 GoogleTokenResponse setAccessToken
@Override
public GoogleTokenResponse setAccessToken(String accessToken)
From source file:org.gatein.security.oauth.google.GoogleProcessorImpl.java
License:Open Source License
@Override public GoogleAccessTokenContext getAccessTokenFromUserProfile(UserProfile userProfile, OAuthCodec codec) { String encodedAccessToken = OAuthPersistenceUtils.getLongAttribute(userProfile, OAuthConstants.PROFILE_GOOGLE_ACCESS_TOKEN, false); String decodedAccessToken = codec.decodeString(encodedAccessToken); // We don't have token in userProfile if (decodedAccessToken == null) { return null; }/* ww w. j av a2s. c o m*/ String encodedRefreshToken = OAuthPersistenceUtils.getLongAttribute(userProfile, OAuthConstants.PROFILE_GOOGLE_REFRESH_TOKEN, false); String decodedRefreshToken = codec.decodeString(encodedRefreshToken); String decodedScope = codec.decodeString(userProfile.getAttribute(OAuthConstants.PROFILE_GOOGLE_SCOPE)); GoogleTokenResponse grc = new GoogleTokenResponse(); grc.setAccessToken(decodedAccessToken); grc.setRefreshToken(decodedRefreshToken); grc.setTokenType("Bearer"); grc.setExpiresInSeconds(1000L); grc.setIdToken("someTokenId"); return new GoogleAccessTokenContext(grc, decodedScope); }
From source file:org.gatein.security.oauth.google.GoogleProcessorImpl.java
License:Open Source License
@Override public void refreshToken(GoogleAccessTokenContext accessTokenContext) { GoogleTokenResponse tokenData = accessTokenContext.getTokenData(); if (tokenData.getRefreshToken() == null) { throw new OAuthException(OAuthExceptionCode.GOOGLE_ERROR, "Given GoogleTokenResponse does not contain refreshToken"); }/*from ww w .j a v a 2 s. c o m*/ try { GoogleRefreshTokenRequest refreshTokenRequest = new GoogleRefreshTokenRequest(TRANSPORT, JSON_FACTORY, tokenData.getRefreshToken(), this.clientID, this.clientSecret); GoogleTokenResponse refreshed = refreshTokenRequest.execute(); // Update only 'accessToken' with new value tokenData.setAccessToken(refreshed.getAccessToken()); if (log.isTraceEnabled()) { log.trace("AccessToken refreshed successfully with value " + refreshed.getAccessToken()); } } catch (IOException ioe) { throw new OAuthException(OAuthExceptionCode.GOOGLE_ERROR, ioe); } }
From source file:org.picketlink.social.standalone.google.GoogleProcessor.java
License:Apache License
/** * Refresh existing access token. Parameter must have attached refreshToken. New refreshed accessToken will be updated to this * instance of accessTokenContext//w ww . j av a 2 s .c o m * * @param accessTokenContext with refreshToken attached */ public void refreshToken(GoogleAccessTokenContext accessTokenContext) { GoogleTokenResponse tokenData = accessTokenContext.getTokenData(); if (tokenData.getRefreshToken() == null) { throw new SocialException(SocialExceptionCode.GOOGLE_ERROR, "Given GoogleTokenResponse does not contain refreshToken"); } try { GoogleRefreshTokenRequest refreshTokenRequest = new GoogleRefreshTokenRequest(TRANSPORT, JSON_FACTORY, tokenData.getRefreshToken(), this.clientID, this.clientSecret); GoogleTokenResponse refreshed = refreshTokenRequest.execute(); // Update only 'accessToken' with new value tokenData.setAccessToken(refreshed.getAccessToken()); if (log.isTraceEnabled()) { log.trace("AccessToken refreshed successfully with value " + refreshed.getAccessToken()); } } catch (IOException ioe) { throw new SocialException(SocialExceptionCode.GOOGLE_ERROR, ioe.getMessage(), ioe); } }