getProviderTokens
Retrieve the full set of OAuth tokens for a connected provider, from the client.
The getProviderTokens client method retrieves the full set of OAuth tokens (access token, refresh token, and ID token) for a specific connected provider, from a client-side or browser context.
import { authClient } from "@/lib/auth-client"
const { success, tokens } = await authClient.getProviderTokens("github")This is the advanced version of getAccessToken, which only returns the access token. Use this if you need the full token set.
See getAccessToken for the simpler alternative.
Reference
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| providerId | string | Yes | The id of the OAuth provider to retrieve the tokens for. |
Returns
| Return Type | Description |
|---|---|
Promise<ProviderTokensReturn> | Resolves to an object containing success and tokens. |
Behavior
- Cookies are read automatically from the browser context — you don't need to handle them or CSRF tokens manually.
- Follows the same access-token → refresh-token fallback described in
api.getProviderTokens. If neither is valid, resolves tosuccess: falseandtokens: null.
Usage
Get a provider's tokens
import { authClient } from "@/lib/auth-client"
const { success, tokens } = await authClient.getProviderTokens("github")Using a token in a request
import { authClient } from "@/lib/auth-client"
const { success, tokens } = await authClient.getProviderTokens("github")
if (!success) {
window.location.assign("/login")
}
const response = await fetch("/api/some-protected-route", {
headers: {
Authorization: `Bearer ${tokens?.accessToken}`,
},
})