Skip to main content

Overview

The @atproto/oauth-client-node package provides a complete OAuth client implementation for Node.js environments. It’s ideal for backend services, traditional web applications, and desktop apps built with Electron.
This package is optimized for server-side OAuth flows with enhanced security features like private_key_jwt authentication and longer token lifetimes.

Installation

Requirements

  • Node.js 18.7.0 or higher
  • Built-in crypto module support
  • Storage backend (database, Redis, etc.)

Quick Start

Backend Web Application

NodeOAuthClient Class

Constructor

Creates a new Node.js OAuth client.
OAuthClientMetadataInput
required
Client metadata configuration.Backend clients should use:
Native/mobile apps should use:
Keyset | Iterable<Key>
Private keys for client authentication. Required when using private_key_jwt.
'query' | 'form_post'
default:"'query'"
OAuth response mode:
  • query: Parameters in URL query string (recommended)
  • form_post: Parameters via HTTP POST body
fragment mode is not supported in Node.js (browser only).
NodeSavedStateStore
required
Storage for OAuth state during authorization flows.
State should be deleted after 1 hour.
NodeSavedSessionStore
required
Storage for authenticated sessions.
string | URL | HandleResolver
Handle resolver service. For Node.js, uses DNS resolution by default.
RuntimeLock
Lock mechanism to prevent concurrent token refreshes across multiple instances.Required for multi-instance deployments (horizontal scaling).
RuntimeImplementation
Custom runtime implementation. Defaults to Node.js crypto.
Fetch
Custom fetch implementation.
string
PLC directory URL for DID resolution.
boolean
default:"false"
Allow HTTP for development. Never use in production.

Methods

The NodeOAuthClient extends OAuthClient and inherits all its methods:

authorize

See OAuthClient.authorize for full documentation. Example:

callback

See OAuthClient.callback for full documentation. Example:

restore

Restores a session from storage. See OAuthClient.restore. Example:

revoke

Revokes a session. See OAuthClient.revoke. Example:

Properties

Jwks
Public JWKS for exposing at jwks_uri.
ClientMetadata
The validated client metadata.

Storage Implementation

State Store Example

Session Store Example

Private Key Management

Generating Keys

Loading Keys

Key Rotation

Complete Express Example

Background Jobs

Event Handling

Error Handling

Security Best Practices

Private Key Security

Never commit private keys to version control. Use environment variables or key management services.

Session Storage

Request Lock

HTTPS Only

Testing

@atproto/oauth-client

Core OAuth client library

@atproto/oauth-client-browser

Browser OAuth client

@atproto/crypto

Cryptographic operations and key management

@atproto/api

High-level API client

TypeScript Types