Skip to main content

expo-auth-session

Version: 55.0.4 Expo module for browser-based authentication using OAuth 2.0 and OpenID Connect. Supports authentication flows with providers like Google, Facebook, GitHub, and custom OAuth servers.

Installation

Usage

API Reference

Hooks

(config: AuthRequestConfig, discovery: DiscoveryDocument) => [AuthRequest | null, AuthSessionResult | null, (options?: AuthRequestPromptOptions) => Promise<AuthSessionResult>]
Hook for creating and managing auth requestsReturns [request, response, promptAsync]
(issuer: string) => DiscoveryDocument | null
Auto-discovers OAuth configuration from issuer

Methods

(options?: MakeRedirectUriOptions) => string
Generates redirect URI for your app
(config: AccessTokenRequestConfig, discovery: DiscoveryDocument) => Promise<TokenResponse>
Exchanges authorization code for access token
(config: RefreshTokenRequestConfig, discovery: DiscoveryDocument) => Promise<TokenResponse>
Refreshes an access token using refresh token
(config: RevokeTokenRequestConfig, discovery: DiscoveryDocument) => Promise<void>
Revokes an access or refresh token
(issuer: string) => Promise<DiscoveryDocument>
Fetches OAuth discovery document

Types

AuthRequestConfig

string
required
OAuth client ID
string
required
Redirect URI for callback
string[]
OAuth scopes to request
ResponseType
OAuth response type (default: 'code')
string
State parameter for CSRF protection
string
PKCE code challenge
'S256' | 'plain'
PKCE code challenge method

TokenResponse

string
Access token
string | undefined
Refresh token (if available)
number
Token expiration time in seconds
string
Token type (usually “Bearer”)
string | undefined
OpenID Connect ID token

Examples

Google Sign-In

GitHub OAuth

Auto Discovery

Token Refresh

Complete Auth Flow

Platform Support

Configuration

app.json

Best Practices

  1. Use PKCE: Always use PKCE for authorization code flow
  2. Secure Storage: Store tokens in SecureStore, not AsyncStorage
  3. Token Refresh: Implement token refresh logic for better UX
  4. Error Handling: Handle auth errors and cancellations gracefully
  5. Deep Linking: Configure proper URL schemes for redirects
Always call WebBrowser.maybeCompleteAuthSession() at the top of your component to handle redirect completion properly.

Resources