Android APIs
public static interface

GoogleApiClient.ServerAuthCodeCallbacks

com.google.android.gms.common.api.GoogleApiClient.ServerAuthCodeCallbacks

Class Overview

Provides callbacks to facilitate the server auth code retrieval and eliminates clients from manipulating background threads to do network communications with their own server.

Server auth code retrieving flow will look like below:

  1. If client knows they have a server counterpart that needs offline access, requestServerAuthCode(String, GoogleApiClient.ServerAuthCodeCallbacks) should be invoked.
  2. If offline access is requested, onCheckServerAuthorization(String, Set) callback will allow client to check their server whether it already has a refresh token so that server auth code retrieval can be skipped.
  3. If server auth code retrieval is necessary, framework will ask for it from auth backend.
  4. A consent will be shown to user to acknowledge granting offline access.
  5. A server auth code will be returned from auth backend if user consents.
  6. onUploadServerAuthCode(String, String) callback will allow client to send the auth code to their own server.

Framework will invoke the callbacks on a background thread. It's NOT necessary to spawn background thread on your own for the network communication.

Summary

Nested Classes
class GoogleApiClient.ServerAuthCodeCallbacks.CheckResult The result holder for onCheckServerAuthorization(String, Set) which contains below information:
  • Whether the server needs a server auth code to exchange for a refresh token. 
Public Methods
abstract GoogleApiClient.ServerAuthCodeCallbacks.CheckResult onCheckServerAuthorization(String idToken, Set<Scope> scopeSet)
Called when client should check with their own web server whether it needs a (new) server auth code to exchange for a (new) refresh token for the given account.
abstract boolean onUploadServerAuthCode(String idToken, String serverAuthCode)
Called when server auth code has been fetched and client should upload it to their own server.

Public Methods

public abstract GoogleApiClient.ServerAuthCodeCallbacks.CheckResult onCheckServerAuthorization (String idToken, Set<Scope> scopeSet)

Called when client should check with their own web server whether it needs a (new) server auth code to exchange for a (new) refresh token for the given account.

This callback happens on a background thread and it's OK to do network communication in this callback.

Parameters
idToken id token for the specific account.
scopeSet an unmodifiable scope set which client side is planning to request access with. If only your server does data access or your client side doesn't user GoogleApiClient to do Google API access, then this scope set will be empty. If your server / client have distinct functionality or your server can figure out their required scopes without knowing what your side is doing, then you can ignore this input as well.
Returns

public abstract boolean onUploadServerAuthCode (String idToken, String serverAuthCode)

Called when server auth code has been fetched and client should upload it to their own server.

This callback happens on a background thread and it's OK to do network communication in this callback.

Parameters
idToken id token for the specific account.
serverAuthCode the server auth code to be uploaded to the 3rd party web server.
Returns
  • Whether 3rd party web server successfully exchanged for a refresh token. Note that returning false will fail the connect(). If client wants to ignore their server auth code exchange failure, they should always return true.