Skip to main content

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
This is a server-side package for authorization servers. If you’re building a client application, use @atproto/oauth-client-node or @atproto/oauth-client-browser instead.

Quick Start

OAuthProvider Class

Constructor

Creates a new OAuth provider instance.
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:
  • AccountStore
  • ClientStore
  • DeviceStore
  • RequestStore
  • TokenStore
  • LexiconStore
  • ReplayStore
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

Returns Express middleware that handles all OAuth endpoints.
ErrorHandler
Custom error handler for OAuth errors.
Example:

authenticateRequest

Authenticates an incoming HTTP request by validating the access token.
Request
required
HTTP request with Authorization header.
string[]
Required audience values.
string[]
Required scopes.
AccessTokenPayload
Decoded and validated token payload.
Example:

Storage Interfaces

AccountStore

Manages user accounts and authentication.
Example Implementation:

ClientStore

Manages OAuth client registrations.
Example:

TokenStore

Manages access and refresh tokens.
Example:

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 metadata
  • GET /.well-known/openid-configuration - OpenID configuration
  • GET /oauth/authorize - Authorization endpoint
  • POST /oauth/token - Token endpoint
  • POST /oauth/revoke - Revocation endpoint
  • POST /oauth/par - Pushed authorization request
  • GET /oauth/jwks - JSON Web Key Set

Security Considerations

Key Management

Rate Limiting

Replay Protection

@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

TypeScript Types