@Beta public final class DataStoreCredentialRefreshListener extends Object implements CredentialRefreshListener
Beta It needs to be added as a refresh listener using Credential.Builder.addRefreshListener(com.google.api.client.auth.oauth2.CredentialRefreshListener). Sample usage:
static void addDataStoreCredentialRefreshListener(
Credential.Builder credentialBuilder, String userId, DataStoreFactory dataStoreFactory)
throws IOException {
credentialBuilder.addRefreshListener(
new DataStoreCredentialRefreshListener(userId, dataStoreFactory));
}
| Constructor and Description |
|---|
DataStoreCredentialRefreshListener(String userId,
com.google.api.client.util.store.DataStore<StoredCredential> credentialDataStore) |
DataStoreCredentialRefreshListener(String userId,
com.google.api.client.util.store.DataStoreFactory dataStoreFactory)
Constructor using
StoredCredential.getDefaultDataStore(DataStoreFactory) for the stored
credential data store. |
| Modifier and Type | Method and Description |
|---|---|
com.google.api.client.util.store.DataStore<StoredCredential> |
getCredentialDataStore()
Returns the stored credential data store.
|
void |
makePersistent(Credential credential)
Stores the updated credential in the credential store.
|
void |
onTokenErrorResponse(Credential credential,
TokenErrorResponse tokenErrorResponse)
Notifies of an error token response from
Credential.refreshToken(). |
void |
onTokenResponse(Credential credential,
TokenResponse tokenResponse)
Notifies of a successful token response from
Credential.refreshToken(). |
public DataStoreCredentialRefreshListener(String userId, com.google.api.client.util.store.DataStoreFactory dataStoreFactory) throws IOException
StoredCredential.getDefaultDataStore(DataStoreFactory) for the stored
credential data store.userId - user ID whose credential is to be updateddataStoreFactory - data store factoryIOExceptionpublic DataStoreCredentialRefreshListener(String userId, com.google.api.client.util.store.DataStore<StoredCredential> credentialDataStore)
userId - user ID whose credential is to be updatedcredentialDataStore - stored credential data storepublic void onTokenResponse(Credential credential, TokenResponse tokenResponse) throws IOException
CredentialRefreshListenerCredential.refreshToken().
Typical use is to provide functionality like persisting the access token in a data store.
Implementations can assume proper thread synchronization is already taken care of inside Credential.refreshToken(). Implementations can also assume that Credential.setAccessToken(java.lang.String), Credential.setRefreshToken(java.lang.String), and Credential.setExpiresInSeconds(java.lang.Long) have already been called previously with the information from
the TokenResponse.
onTokenResponse in interface CredentialRefreshListenercredential - credential on which the token refresh appliedtokenResponse - token responseIOExceptionpublic void onTokenErrorResponse(Credential credential, TokenErrorResponse tokenErrorResponse) throws IOException
CredentialRefreshListenerCredential.refreshToken().
Typical use is to provide functionality like removing persistence of the access token from
the data store. Implementations can assume proper thread synchronization is already taken care
of inside Credential.refreshToken(). Implementations can also assume that Credential.setAccessToken(java.lang.String), and Credential.setExpiresInSeconds(java.lang.Long) have already been called
previously with null to clear their values.
onTokenErrorResponse in interface CredentialRefreshListenercredential - credential on which the token refresh appliedtokenErrorResponse - token error response or null for none suppliedIOExceptionpublic com.google.api.client.util.store.DataStore<StoredCredential> getCredentialDataStore()
public void makePersistent(Credential credential) throws IOException
IOExceptionCopyright © 2011–2024 Google. All rights reserved.