List of usage examples for com.google.api.client.googleapis.auth.oauth2 GoogleTokenResponse setRefreshToken
@Override
public GoogleTokenResponse setRefreshToken(String refreshToken)
From source file:com.philbeaudoin.quebec.server.user.OAuthManagerImpl.java
License:Apache License
@Override public String mergeTokenResponses(String oldestString, String newestString) throws IOException { GoogleTokenResponse newest = jsonFactory.fromString(newestString, GoogleTokenResponse.class); if (newest.getRefreshToken() == null && oldestString != null) { GoogleTokenResponse oldest = jsonFactory.fromString(oldestString, GoogleTokenResponse.class); newest.setRefreshToken(oldest.getRefreshToken()); }/*ww w.jav a 2s .c om*/ return newest.toString(); }
From source file:org.alfresco.integrations.google.docs.service.GoogleDocsServiceImpl.java
License:Open Source License
public boolean completeAuthentication(String authorizationCode) throws GoogleDocsServiceException, IOException { boolean authenticationComplete = false; GoogleTokenResponse response = getFlow().newTokenRequest(authorizationCode) .setRedirectUri(GoogleDocsConstants.REDIRECT_URI).execute(); try {// w w w .j av a 2 s .c o m // If this is a reauth....we may not get back the refresh token. We // need to make sure it is persisted across the "refresh". if (response.getRefreshToken() == null) { log.debug("Missing Refresh Token"); OAuth2CredentialsInfo credentialInfo = oauth2CredentialsStoreService .getPersonalOAuth2Credentials(GoogleDocsConstants.REMOTE_SYSTEM); // In the "rare" case that no refresh token is returned and the // users credentials are no longer there we need to skip this // next check if (credentialInfo != null) { // If there is a persisted refresh ticket...add it to the // accessGrant so that it is persisted across the update if (credentialInfo.getOAuthRefreshToken() != null) { response.setRefreshToken(credentialInfo.getOAuthRefreshToken()); log.debug("Persisting Refresh Token across reauth"); } } } oauth2CredentialsStoreService.storePersonalOAuth2Credentials(GoogleDocsConstants.REMOTE_SYSTEM, response.getAccessToken(), response.getRefreshToken(), new Date(response.getExpiresInSeconds()), new Date()); authenticationComplete = true; } catch (NoSuchSystemException nsse) { throw new GoogleDocsServiceException(nsse.getMessage()); } log.debug("Authentication Complete: " + authenticationComplete); return authenticationComplete; }
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; }/* w ww . ja va 2 s . com*/ 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); }