Class DataStoreCredentialRefreshListener (1.36.0)

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
Name Description
userId String

user ID whose credential is to be updated

credentialDataStore com.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
Name Description
userId String

user ID whose credential is to be updated

dataStoreFactory com.google.api.client.util.store.DataStoreFactory

data store factory

Methods

getCredentialDataStore()

public DataStore<StoredCredential> getCredentialDataStore()

Returns the stored credential data store.

Returns
Type Description
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
Name Description
credential Credential
Exceptions
Type Description
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
Name Description
credential Credential
tokenErrorResponse TokenErrorResponse
Exceptions
Type Description
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
Name Description
credential Credential
tokenResponse TokenResponse
Exceptions
Type Description
IOException