/** * Loads the Credential for the user from the underlying {@link DataStore}. * @throws AuthException If the credential could not be loaded. */ public Credential loadCredential(String userId) throws AuthException { try { return authorizationCodeFlow.loadCredential(userId); } catch (IOException e) { throw new AuthException("Unable to load credential.", e); } }
/** * Clears the credential for the user in the underlying (@link DateStore}. * @throws AuthException If the credential could not be cleared. */ public void clearCredential(String userId) throws AuthException { try { authorizationCodeFlow.getCredentialDataStore().delete(userId); } catch (IOException e) { throw new AuthException("Unable to clear credential.", e); } }
/** * Authenticates using the authorization code for the user and stores the Credential in the * underlying {@link DataStore}. * @throws AuthException If the credential could not be created. */ public Credential authenticate(String authorizationCode, String userId) throws AuthException { Preconditions.checkNotNull(authorizationCode, "Authorization code must not be null"); AuthorizationCodeTokenRequest tokenRequest = authorizationCodeFlow.newTokenRequest(authorizationCode); TokenResponse tokenResponse; try { tokenResponse = tokenRequest .setRedirectUri(redirectUri) .setScopes(scopes) .execute(); } catch (IOException e) { throw new AuthException("Unable to request token.", e); } try { return authorizationCodeFlow.createAndStoreCredential(tokenResponse, userId); } catch (IOException e) { throw new AuthException("Unable to create and store credential.", e); } }