Tokens and sessions
Stored session
Both platforms keep the signed-in session on the device: in the Keychain on iOS and in Keystore-encrypted storage on Android. getCurrentUser() returns it synchronously, right after launch, before configure, and offline:
const session = GoogleSignIn.getCurrentUser()
if (session !== undefined) showHome(session.user)
The returned session never contains a serverAuthCode. On iOS, the first call that needs Google's tokens (getTokens, requestScopes, revokeAccess) restores the SDK's own session without UI.
Fresh tokens
getTokens() returns an ID token valid for at least five more minutes and a fresh access token. It rejects with SIGN_IN_REQUIRED without a user.
const { idToken, accessToken } = await GoogleSignIn.getTokens()
When you only need the ID token, getIdToken() resolves undefined instead of rejecting when no user is signed in.
How each platform refreshes
- iOS refreshes both tokens silently with its refresh token.
- Android apps never get a refresh token: Credential Manager is the only current Android API that issues Google ID tokens, and only through a sign-in. When the stored ID token expires within five minutes,
getTokens()runs Credential Manager's auto sign-in for the signed-in account. Google shows a brief "Signing in as" bar, or the account sheet when it cannot pick the account itself.
:::warning Android refresh needs the foreground
The Android refresh needs the app in the foreground (NO_PRESENTER otherwise), counts as a sign-in flow for IN_PROGRESS, and rejects with SIGN_IN_CANCELLED when the user dismisses the sheet. Request tokens from foreground code, not background tasks.
:::
Rejected access tokens
When a Google API rejects an access token, discard it so the next getTokens() returns a new one:
const { accessToken } = await GoogleSignIn.getTokens()
const response = await fetch(url, { headers: { Authorization: `Bearer ${accessToken}` } })
if (response.status === 401) {
await GoogleSignIn.clearCachedAccessToken(accessToken)
// Retry once with a fresh token.
}
clearCachedAccessToken resolves without doing anything when the token is not cached, including when no user is signed in.