Skip to main content
GET
Handle OAuth provider callbacks and complete the authentication flow. This endpoint receives the authorization code from OAuth providers and exchanges it for access tokens to authenticate users.
This endpoint is automatically called by OAuth providers after user authorization. You typically don’t call this endpoint directly.

Query Parameters

string
required
Authorization code returned by the OAuth provider.
string
State parameter for CSRF protection (if provided in the authorization request).
string
OAuth provider identifier (may be included in some implementations).
string
Error code if the OAuth authorization failed.
string
Human-readable error description if the OAuth authorization failed.

Response

This endpoint typically returns a 302 Found redirect response to the application’s redirect URL with authentication tokens.
string
Redirect URL with authentication tokens or session information

Error Responses

OAuth Callback Flow

Successful Authentication

  1. Authorization Code Exchange: The auth service exchanges the authorization code for access tokens
  2. User Information Retrieval: Fetch user profile information from the OAuth provider
  3. User Account Management: Create or update user account in the database
  4. Session Creation: Generate authentication tokens for the user
  5. Redirect: Redirect user to the specified redirect URL with tokens

Error Handling

Common OAuth errors and their handling:
  • access_denied: User denied authorization
  • invalid_request: Malformed authorization request
  • unauthorized_client: Client not authorized for this grant type
  • unsupported_response_type: Authorization server doesn’t support the response type
  • invalid_scope: Requested scope is invalid or unknown
  • server_error: Authorization server encountered an error
  • temporarily_unavailable: Authorization server is temporarily unavailable

Implementation Examples

React OAuth Callback Handler

OAuth Token Extraction Hook

Node.js OAuth Callback Handler

OAuth Error Handler Component

Security Considerations

  • State Parameter Validation: Always validate the state parameter to prevent CSRF attacks
  • Authorization Code Expiration: Authorization codes are short-lived (typically 10 minutes)
  • Token Security: Store tokens securely and use HttpOnly cookies when possible
  • Redirect URL Validation: Ensure redirect URLs are whitelisted
  • Error Handling: Don’t expose sensitive error information to users

Callback URL Configuration

Development

Production

Multiple Environments

Best Practices

  • Always validate state parameters
  • Use HTTPS in production
  • Implement proper error handling
  • Store tokens securely
  • Set appropriate cookie flags
  • Show loading states during processing
  • Provide clear error messages
  • Offer alternative authentication methods
  • Handle network failures gracefully
  • Clean URLs after token extraction
  • Log OAuth errors for debugging
  • Provide user-friendly error messages
  • Implement retry mechanisms
  • Handle expired authorization codes
  • Gracefully handle provider downtime

Testing

Unit Tests

OAuth Authorize

Initiate OAuth authorization flow

Login

Traditional email/password login

Get Profile

Get authenticated user profile

Logout

End user sessions