com.google.api.client.auth.oauth2
Class CredentialStoreRefreshListener

java.lang.Object
  extended by com.google.api.client.auth.oauth2.CredentialStoreRefreshListener
All Implemented Interfaces:
CredentialRefreshListener

public final class CredentialStoreRefreshListener
extends Object
implements CredentialRefreshListener

Thread-safe OAuth 2.0 credential refresh listener that stores the refresh token response in the credential store.

It needs to be added as a refresh listener using Credential.Builder.addRefreshListener(com.google.api.client.auth.oauth2.CredentialRefreshListener).

Since:
1.7
Author:
Yaniv Inbar

Constructor Summary
CredentialStoreRefreshListener(String userId, CredentialStore credentialStore)
           
 
Method Summary
 CredentialStore getCredentialStore()
          Returns the credential 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().
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CredentialStoreRefreshListener

public CredentialStoreRefreshListener(String userId,
                                      CredentialStore credentialStore)
Parameters:
userId - user ID whose credential is to be updated
credentialStore - credential store
Method Detail

onTokenResponse

public void onTokenResponse(Credential credential,
                            TokenResponse tokenResponse)
Description copied from interface: CredentialRefreshListener
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(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.

Specified by:
onTokenResponse in interface CredentialRefreshListener
Parameters:
credential - credential on which the token refresh applied
tokenResponse - token response

onTokenErrorResponse

public void onTokenErrorResponse(Credential credential,
                                 TokenErrorResponse tokenErrorResponse)
Description copied from interface: CredentialRefreshListener
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(java.lang.String), and Credential.setExpiresInSeconds(java.lang.Long) have already been called previously with null to clear their values.

Specified by:
onTokenErrorResponse in interface CredentialRefreshListener
Parameters:
credential - credential on which the token refresh applied
tokenErrorResponse - token error response or null for none supplied

getCredentialStore

public CredentialStore getCredentialStore()
Returns the credential store.


makePersistent

public void makePersistent(Credential credential)
Stores the updated credential in the credential store.



Copyright © 2011-2012 Google. All Rights Reserved.