Skip to main content

Overview

The SDK provides built-in proxy support for Auth0’s My Account and My Organization Management APIs, enabling secure browser-initiated requests while maintaining server-side DPoP authentication and token management.
The proxy implements a Backend-for-Frontend (BFF) pattern where tokens and DPoP keys remain on the server while the client can make authenticated API calls through proxy endpoints.

How It Works

The proxy handler automatically intercepts requests to /me/* and /my-org/* paths in your Next.js application and forwards them to the respective Auth0 APIs with proper authentication headers:
  • Tokens and DPoP keys remain on the server
  • Access tokens are automatically retrieved or refreshed
  • DPoP proofs are generated for each request
  • Session updates occur transparently

My Account API Proxy

The My Account API allows users to manage their profile and authentication settings.

Configuration

Configure audience and scopes for the My Account API:
lib/auth0.ts
Replace urn:your-api-identifier with your actual API identifier from the Auth0 Dashboard.

Client-Side Usage

Make requests through the /me proxy path:
app/profile/page.tsx

Updating Profile Data

app/profile/edit/page.tsx

scope Header

The scope header specifies the required scope for the request. The SDK retrieves an access token with the appropriate audience and scope, then forwards the request with authentication headers.

My Organization API Proxy

The My Organization API allows users to manage their organization memberships and settings.

Configuration

Configure audience and scopes for the My Organization API:
lib/auth0.ts

Client-Side Usage

Make requests through the /my-org proxy path:
app/organization/page.tsx

Integration with UI Components

The proxy works seamlessly with Auth0’s UI components like @auth0/auth0-react:
app/components/ProfileWidget.tsx

HTTP Methods

The proxy supports all standard HTTP methods:

CORS Handling

The proxy automatically handles CORS for client-side requests:

Error Handling

Handle errors appropriately based on HTTP status codes:
app/profile/page.tsx

Common Error Codes

Token Management

The proxy automatically handles token management:
  • Token Retrieval: Fetches access tokens with the correct audience and scope
  • Token Refresh: Automatically refreshes expired tokens using refresh tokens
  • Token Caching: Caches tokens to minimize Auth0 API calls
  • DPoP Proofs: Generates DPoP proofs for each request when enabled

Security Considerations

Best Practices

  1. Use HTTPS: Always use HTTPS in production
  2. Validate Scopes: Request only the scopes needed for each operation
  3. Rate Limiting: Implement rate limiting on proxy endpoints
  4. Input Validation: Validate and sanitize all user inputs
  5. Error Messages: Don’t expose sensitive information in error messages

Scope Configuration

Follow the principle of least privilege when configuring scopes:
lib/auth0.ts

Authentication Requirements

The proxy endpoints require an authenticated session. Unauthenticated requests will receive a 401 Unauthorized response.

Debugging

Enable debug logging to troubleshoot proxy issues:
app/api/debug-proxy/route.ts

Advanced Usage

Custom Headers

Pass custom headers through the proxy:

Batch Requests

Make multiple requests efficiently:

Pagination

Handle paginated responses:

API Reference

For complete API documentation, see:

Limitations

  • Proxy endpoints require an active user session
  • DPoP is recommended but not required
  • Rate limits apply based on your Auth0 plan
  • Some endpoints may require additional tenant configuration

Further Reading