@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,
DataStore<StoredCredential> credentialDataStore) |
DataStoreCredentialRefreshListener(String userId,
DataStoreFactory dataStoreFactory)
Constructor using
StoredCredential.getDefaultDataStore(DataStoreFactory) for the stored
credential data store. |
Modifier and Type | Method and Description |
---|---|
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, DataStoreFactory dataStoreFactory) throws IOException
StoredCredential.getDefaultDataStore(DataStoreFactory)
for the stored
credential data store.userId
- user ID whose credential is to be updateddataStoreFactory
- data store factoryIOException
public DataStoreCredentialRefreshListener(String userId, DataStore<StoredCredential> credentialDataStore)
userId
- user ID whose credential is to be updatedcredentialDataStore
- stored credential data storepublic void onTokenResponse(Credential credential, TokenResponse tokenResponse) throws IOException
CredentialRefreshListener
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(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 CredentialRefreshListener
credential
- credential on which the token refresh appliedtokenResponse
- token responseIOException
public void onTokenErrorResponse(Credential credential, TokenErrorResponse tokenErrorResponse) throws IOException
CredentialRefreshListener
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(java.lang.String)
, and Credential.setExpiresInSeconds(java.lang.Long)
have already been called
previously with null
to clear their values.
onTokenErrorResponse
in interface CredentialRefreshListener
credential
- credential on which the token refresh appliedtokenErrorResponse
- token error response or null
for none suppliedIOException
public DataStore<StoredCredential> getCredentialDataStore()
public void makePersistent(Credential credential) throws IOException
IOException
Copyright © 2011–2021 Google. All rights reserved.