Aura Auth
API ReferenceClientFunctions

getAccessToken

Retrieve the OAuth access token for a connected provider, from the client.

The getAccessToken client method retrieves the OAuth access token for a specific connected provider, from a client-side or browser context.

get-access-token.ts
import { authClient } from "@/lib/auth-client"

const accessToken = await authClient.getAccessToken("github")

This is a simplified version of getProviderTokens, which retrieves the full set of OAuth tokens for a provider. See getProviderTokens for the advanced alternative.

Reference

Parameters

ParameterTypeRequiredDescription
providerIdstringYesThe id of the OAuth provider to retrieve the access token for.

Returns

Return TypeDescription
Promise<string | null>Resolves to the access token or null if retrieval fails.

Behavior

  • Cookies are read automatically from the browser context — you don't need to handle them or CSRF tokens manually.
  • If retrieval fails (no valid access or refresh token for the provider), the method resolves to null — this does not throw an error, as "not connected" is an expected outcome.

Usage

Get a provider's access token

get-access-token.ts
import { authClient } from "@/lib/auth-client"

const accessToken = await authClient.getAccessToken("github")

Using the token in a request

protected-fetch.ts
import { authClient } from "@/lib/auth-client"

const accessToken = await authClient.getAccessToken("github")

if (!accessToken) {
  window.location.assign("/login")
}

const response = await fetch("/api/some-protected-route", {
  headers: {
    Authorization: `Bearer ${accessToken}`,
  },
})

On this page