Class DataStoreCredentialRefreshListener
- java.lang.Object
-
- com.google.api.client.auth.oauth2.DataStoreCredentialRefreshListener
-
- All Implemented Interfaces:
CredentialRefreshListener
@Beta public final class DataStoreCredentialRefreshListener extends Object implements CredentialRefreshListener
Beta
Thread-safe OAuth 2.0 credential refresh listener that stores the refresh token response in the credential data store.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)); }
- Since:
- 1.6
- Author:
- Yaniv Inbar
-
-
Constructor Summary
Constructors Constructor 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 usingStoredCredential.getDefaultDataStore(DataStoreFactory)
for the stored credential data store.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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 fromCredential.refreshToken()
.void
onTokenResponse(Credential credential, TokenResponse tokenResponse)
Notifies of a successful token response fromCredential.refreshToken()
.
-
-
-
Constructor Detail
-
DataStoreCredentialRefreshListener
public DataStoreCredentialRefreshListener(String userId, com.google.api.client.util.store.DataStoreFactory dataStoreFactory) throws IOException
Constructor usingStoredCredential.getDefaultDataStore(DataStoreFactory)
for the stored credential data store.- Parameters:
userId
- user ID whose credential is to be updateddataStoreFactory
- data store factory- Throws:
IOException
-
DataStoreCredentialRefreshListener
public DataStoreCredentialRefreshListener(String userId, com.google.api.client.util.store.DataStore<StoredCredential> credentialDataStore)
- Parameters:
userId
- user ID whose credential is to be updatedcredentialDataStore
- stored credential data store
-
-
Method Detail
-
onTokenResponse
public void onTokenResponse(Credential credential, TokenResponse tokenResponse) throws IOException
Description copied from interface:CredentialRefreshListener
Notifies of a successful token response fromCredential.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 thatCredential.setAccessToken(java.lang.String)
,Credential.setRefreshToken(java.lang.String)
, andCredential.setExpiresInSeconds(java.lang.Long)
have already been called previously with the information from theTokenResponse
.- Specified by:
onTokenResponse
in interfaceCredentialRefreshListener
- Parameters:
credential
- credential on which the token refresh appliedtokenResponse
- token response- Throws:
IOException
-
onTokenErrorResponse
public void onTokenErrorResponse(Credential credential, TokenErrorResponse tokenErrorResponse) throws IOException
Description copied from interface:CredentialRefreshListener
Notifies of an error token response fromCredential.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 thatCredential.setAccessToken(java.lang.String)
, andCredential.setExpiresInSeconds(java.lang.Long)
have already been called previously withnull
to clear their values.- Specified by:
onTokenErrorResponse
in interfaceCredentialRefreshListener
- Parameters:
credential
- credential on which the token refresh appliedtokenErrorResponse
- token error response ornull
for none supplied- Throws:
IOException
-
getCredentialDataStore
public com.google.api.client.util.store.DataStore<StoredCredential> getCredentialDataStore()
Returns the stored credential data store.
-
makePersistent
public void makePersistent(Credential credential) throws IOException
Stores the updated credential in the credential store.- Throws:
IOException
-
-