Class DataStoreCredentialRefreshListener (1.33.3)

public final class DataStoreCredentialRefreshListener 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. Sample usage:

static void addDataStoreCredentialRefreshListener( Credential.Builder credentialBuilder, String userId, DataStoreFactory dataStoreFactory) throws IOException { credentialBuilder.addRefreshListener( new DataStoreCredentialRefreshListener(userId, dataStoreFactory)); }

Inheritance

java.lang.Object > DataStoreCredentialRefreshListener

Constructors

DataStoreCredentialRefreshListener(String userId, DataStore<StoredCredential> credentialDataStore)

public DataStoreCredentialRefreshListener(String userId, DataStore<StoredCredential> credentialDataStore)
Parameters
NameDescription
userIdString

user ID whose credential is to be updated

credentialDataStorecom.google.api.client.util.store.DataStore<StoredCredential>

stored credential data store

DataStoreCredentialRefreshListener(String userId, DataStoreFactory dataStoreFactory)

public DataStoreCredentialRefreshListener(String userId, DataStoreFactory dataStoreFactory)

Constructor using StoredCredential#getDefaultDataStore(DataStoreFactory) for the stored credential data store.

Parameters
NameDescription
userIdString

user ID whose credential is to be updated

dataStoreFactorycom.google.api.client.util.store.DataStoreFactory

data store factory

Methods

getCredentialDataStore()

public DataStore<StoredCredential> getCredentialDataStore()

Returns the stored credential data store.

Returns
TypeDescription
com.google.api.client.util.store.DataStore<StoredCredential>

makePersistent(Credential credential)

public void makePersistent(Credential credential)

Stores the updated credential in the credential store.

Parameter
NameDescription
credentialCredential
Exceptions
TypeDescription
IOException

onTokenErrorResponse(Credential credential, TokenErrorResponse tokenErrorResponse)

public void onTokenErrorResponse(Credential credential, TokenErrorResponse tokenErrorResponse)

Notifies of an error token response from Credential#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, and Credential#setExpiresInSeconds have already been called previously with null to clear their values.

Parameters
NameDescription
credentialCredential
tokenErrorResponseTokenErrorResponse
Exceptions
TypeDescription
IOException

onTokenResponse(Credential credential, TokenResponse tokenResponse)

public void onTokenResponse(Credential credential, TokenResponse tokenResponse)

Notifies of a successful token response from Credential#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, Credential#setRefreshToken, and Credential#setExpiresInSeconds have already been called previously with the information from the TokenResponse.

Parameters
NameDescription
credentialCredential
tokenResponseTokenResponse
Exceptions
TypeDescription
IOException