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
- Use PKCE: Always use PKCE for authorization code flow
- Secure Storage: Store tokens in SecureStore, not AsyncStorage
- Token Refresh: Implement token refresh logic for better UX
- Error Handling: Handle auth errors and cancellations gracefully
- Deep Linking: Configure proper URL schemes for redirects