List of usage examples for com.google.api.client.googleapis.auth.oauth2 GoogleRefreshTokenRequest execute
@Override public GoogleTokenResponse execute() throws IOException
From source file:com.github.jdavisonc.camel.gdrive.GDriveEndpoint.java
License:Apache License
public GoogleTokenResponse refreshToken(String refreshToken) throws IOException { String clientId = getConfiguration().getClientId(); String clientSecret = getConfiguration().getClientSecret(); if (clientId == null || clientSecret == null) { return null; }/*from ww w . j av a 2 s . c o m*/ if (refreshToken == null) { refreshToken = getConfiguration().getRefreshToken(); } GoogleRefreshTokenRequest refresh = new GoogleRefreshTokenRequest(httpTransport, jsonFactory, refreshToken, clientId, clientSecret); return refresh.execute(); }
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 w w w .j ava 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//ww w . j a va 2s . 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); } }
From source file:org.sociotech.communitymashup.source.google.urlshortener.GoogleUrlShortenerSourceService.java
License:Open Source License
/** * Refreshes the access token if it expires soon *//*from www . ja va2s .c o m*/ private void refreshTokenIfNeeded() { // is expired or expires in the next 5 minutes if (expirationTime - System.currentTimeMillis() < 5000) { // refresh token log("Access token is expired, so refresh it", LogService.LOG_DEBUG); GoogleRefreshTokenRequest tokenRequest = new GoogleRefreshTokenRequest(new NetHttpTransport(), new JacksonFactory(), refreshToken, clientID, clientSecret); // execute request try { // indicate token update tokenUpdate = true; GoogleTokenResponse googleToken = tokenRequest.execute(); expirationTime = System.currentTimeMillis() + 1000 * googleToken.getExpiresInSeconds(); // store access token accessToken = googleToken.getAccessToken(); source.addProperty(GoogleUrlShortenerProperties.ACCESS_TOKEN_PROPERTY, accessToken); // store access token expiration date source.addProperty(GoogleUrlShortenerProperties.ACCESS_TOKEN_EXPIRATION_PROPERTY, "" + expirationTime); // recreate shortener instance instantiateAuthorizedShortener(); } catch (IOException e) { log("Could not refresh access token (" + e.getMessage() + ")", LogService.LOG_WARNING); } finally { // finished token update tokenUpdate = false; } } }
From source file:utils.gce.auth.GoogleComputeEngineAuthImpl.java
License:Apache License
private GoogleTokenResponse getAccessToken() throws IOException { GoogleRefreshTokenRequest refreshTokenRequest = new GoogleRefreshTokenRequest(HTTP_TRANSPORT, JSON_FACTORY, refreshToken, clientId, clientSecret); return refreshTokenRequest.execute(); }