OAuth replaces the deprecated app password authentication method. All new applications should use OAuth.
Why OAuth?
OAuth provides several advantages over app passwords:- Better security: No need to handle user passwords
- Longer token lifetimes: Especially when using private key authentication
- Standardized flow: Works the same across all AT Protocol servers
- Automatic token refresh: Tokens refresh transparently
- Revocation support: Users can revoke access without changing their password
Choosing an OAuth Client
AT Protocol provides OAuth clients for different environments:Browser
@atproto/oauth-client-browser for single-page applications (SPAs)Node.js
@atproto/oauth-client-node for backend services and desktop appsCore
@atproto/oauth-client for custom implementationsBrowser OAuth Setup
For single-page applications without a backend.Installation
Client Metadata
First, create and host your client metadata as a JSON file:client-metadata.json
The
client_id must be the URL where this metadata file is hosted. It must be publicly accessible.Initializing the Client
Handle Resolver Options
You can use different handle resolvers:Initialize on App Load
Callinit() once when your app loads:
Sign In Flow
Using the Session
After authentication, create anAgent with the session:
Session Management
Listen for session changes:Node.js OAuth Setup
For backend services, traditional web apps, and desktop applications.Installation
Generate Keys
For backend services, you need to generate private keys:Client Setup (Backend Service)
Express Integration
Native App Setup
For desktop apps (Electron, etc.):Native apps use
token_endpoint_auth_method: "none" because they cannot safely store private keys. This results in shorter token lifetimes.Advanced Features
Silent Sign-In
Attempt to sign in without user interaction:Request Locking
Prevent concurrent token refreshes across multiple instances:Custom Locales
Development and Testing
Localhost Development
AT Protocol OAuth supports loopback clients for development:- Must use
http://127.0.0.1:<port>orhttp://[::1]:<port> - No custom client metadata
- Very short token lifetimes (typically 1 day)
- No silent sign-in
Error Handling
Best Practices
1
Use backend OAuth when possible
Backend OAuth provides better security and longer token lifetimes. Use browser OAuth only for pure client-side apps.
2
Implement session listeners
Always listen for session deletion events to handle token expiration gracefully.
3
Store sessions securely
Use appropriate storage for your platform:
- Browser: IndexedDB (automatic with browser client)
- Backend: Encrypted database
- Desktop: OS keychain (e.g., keytar)
4
Handle offline users
Tokens can expire while users are offline. Implement proper error handling:
5
Use state parameter
Use the state parameter to maintain context across the OAuth flow:
Security Considerations
Migration from App Passwords
If you’re migrating from app password authentication:Next Steps
Using the API
Learn how to use the Agent API with your OAuth session
Rich Text
Work with mentions and links in posts
Moderation
Implement content moderation
Development Setup
Set up your local development environment