Overview
The@atproto/oauth-provider package provides a complete OAuth 2.0 and OpenID Connect authorization server implementation for Node.js. It’s designed specifically for AT Protocol and includes all required features for PDS (Personal Data Server) implementations.
This package is primarily used by PDS implementations. Most application developers should use the client packages instead.
Installation
Requirements
- Node.js 18.7.0 or higher
- Storage backend (database)
- Redis (optional, for replay protection and distributed deployments)
When to Use This Package
Use@atproto/oauth-provider when:
- Implementing a PDS (Personal Data Server)
- Building a custom AT Protocol authorization server
- Running your own OAuth infrastructure
Quick Start
OAuthProvider Class
Constructor
string | URL
required
The issuer identifier (base URL) of the authorization server.
Keyset | Iterable<Key>
required
Private keys for signing tokens and credentials.
Store
Single store implementation for all storage needs. Can implement multiple interfaces:
AccountStoreClientStoreDeviceStoreRequestStoreTokenStoreLexiconStoreReplayStore
AccountStore
Storage for user accounts. Required if not provided via
store.ClientStore
Storage for OAuth clients. Required if not provided via
store.DeviceStore
Storage for device/session information. Required if not provided via
store.RequestStore
Storage for authorization requests. Required if not provided via
store.TokenStore
Storage for tokens and refresh tokens. Required if not provided via
store.LexiconStore
Storage for lexicon schemas (optional).
ReplayStore
Storage for replay protection (optional, uses memory by default).
Redis | RedisOptions | string
Redis connection for replay protection and distributed deployments.
OAuthHooks
Lifecycle hooks for customization and integration.
number
default:"86400000"
Maximum age (ms) for authentication sessions before requiring re-authentication.
Default: 24 hours.
number
default:"3600000"
Maximum age (ms) for access tokens before requiring refresh.
Default: 1 hour.
AccessTokenMode
default:"AccessTokenMode.stateless"
Token mode:
stateless: Self-contained tokens (recommended)light: Token ID only, requires database lookup
CustomMetadata
Additional metadata for the discovery document.
LexResolver
Lexicon resolver for schema validation.
Fetch
Custom fetch implementation for retrieving client metadata.
Methods
middleware
ErrorHandler
Custom error handler for OAuth errors.
authenticateRequest
Request
required
HTTP request with Authorization header.
string[]
Required audience values.
string[]
Required scopes.
AccessTokenPayload
Decoded and validated token payload.
Storage Interfaces
AccountStore
Manages user accounts and authentication.ClientStore
Manages OAuth client registrations.TokenStore
Manages access and refresh tokens.OAuth Hooks
Hooks provide integration points for custom logic:onSignedIn
Called when a user successfully signs in.onSignedUp
Called when a new user signs up.onAuthorized
Called when a client is authorized.onTokenCreated
Called when an access token is created.onTokenRefreshed
Called when a token is refreshed.onCreateToken
Modify token claims before creation.onDecodeToken
Modify or validate token after decoding.Customization
Branding
Customize the authorization UI.Custom Error Handler
Complete Example
OAuth Endpoints
The provider automatically creates these endpoints:GET /.well-known/oauth-authorization-server- Server metadataGET /.well-known/openid-configuration- OpenID configurationGET /oauth/authorize- Authorization endpointPOST /oauth/token- Token endpointPOST /oauth/revoke- Revocation endpointPOST /oauth/par- Pushed authorization requestGET /oauth/jwks- JSON Web Key Set
Security Considerations
Key Management
Rate Limiting
Replay Protection
Related Packages
@atproto/oauth-client-node
Node.js OAuth client
@atproto/oauth-client-browser
Browser OAuth client
@atproto/pds
Personal Data Server implementation
@atproto/crypto
Cryptographic operations and key management