node-oauth2-server

Framework-agnostic, RFC 6749/6750-compliant OAuth 2.0 server module for Node.js with native async/await and PKCE support.

Library
npm
v5.3.0
446stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
84/100Excellent
Development Activity96
Maintenance84
Community72
Maturity56
Momentum28

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
83/100Excellent
Architecture85
Code Quality88
Innovation78
Learning Curve80

@node-oauth/oauth2-server is a complete OAuth 2.0 server implementation for Node.js, forked from the abandoned oauthjs/node-oauth2-server to keep the project actively maintained. It implements the authorization_code, client_credentials, refresh_token, and password grants (plus custom extension grants) fully compliant with RFC 6749 and the Bearer Token usage spec RFC 6750, and supports PKCE for public clients per OAuth 2.1 guidance.

The module is deliberately framework- and storage-agnostic: it defines a Model interface your application implements against whatever persistence layer you already use (PostgreSQL, MySQL, MongoDB, Redis, or anything else), and a Request/Response abstraction that decouples the library from any specific HTTP framework. Official wrapper packages (such as an Express adapter) exist for teams that want a drop-in middleware, while the core library stays usable standalone.

What You Get

  • Full support for authorization_code, client_credentials, refresh_token, and password grants, plus a documented extension-grant mechanism for custom flows
  • RFC 6749 and RFC 6750 compliance out of the box, including correct error codes and WWW-Authenticate header handling
  • Built-in PKCE support (with an opt-in plain challenge method and an opt-in requirePKCE enforcement flag) for securing public clients
  • A storage-agnostic Model interface so tokens, clients, and users can live in any database — Postgres, MySQL, MongoDB, Redis, or a custom store
  • First-class async/await throughout, with no callback-based legacy API to work around
  • TypeScript type definitions (index.d.ts) shipped in the package for editor autocomplete and compile-time checks

Common Use Cases

  • Adding a self-hosted OAuth 2.0 authorization server to a Node.js API instead of depending on a third-party identity provider
  • Issuing and validating bearer access tokens and refresh tokens for a first-party mobile or SPA client using the authorization_code grant with PKCE
  • Securing service-to-service calls with the client_credentials grant
  • Building a custom identity/auth layer on top of an existing user database via the Model interface, rather than migrating users to a hosted auth provider
  • Implementing a custom extension grant type (e.g. a device-code or SAML-bearer flow) on top of the library’s AbstractGrantType base class

Under The Hood

Architecture The TokenHandler validates the incoming request, extracts client credentials via HTTP Basic auth or body parameters (with PKCE-aware fallbacks for public clients), and delegates to one of four grant-type classes (AuthorizationCodeGrantType, ClientCredentialsGrantType, PasswordGrantType, RefreshTokenGrantType), each extending a shared AbstractGrantType base that provides token generation, expiry calculation, and scope validation against the application’s Model. AuthorizeHandler and AuthenticateHandler follow the same layered shape for the authorization and resource-protection flows. Errors flow through a class hierarchy rooted in OAuthError, with each subclass mapping to a specific RFC error code, and non-OAuth errors are normalized to ServerError before reaching the client. The only integration points into an application are the Request/Response wrapper classes and the Model interface, so the core handlers and grant types never depend on a specific HTTP framework or storage engine.

Tech Stack Runtime dependencies are minimal: @node-oauth/formats for RFC ABNF format validation, basic-auth for HTTP Basic credential parsing, and type-is for content-type checks — no bundled web framework or ORM. Linting and formatting run through Biome rather than ESLint/Prettier, tests run on Mocha with Chai assertions and Sinon stubs, coverage is measured with nyc, and the documentation site is built with VitePress from JSDoc comments via a custom docs/build-api.js script. Type definitions in index.d.ts are hand-maintained rather than generated. The package targets Node >=16 and ships as plain CommonJS with no build step required by consumers.

Code Quality The test suite is organized into three tiers — test/unit, test/integration, and test/compliance — with the compliance tier specifically covering full RFC-conformance workflows (client authentication, PKCE, password grant, refresh-token grant). CI runs Biome lint/format checks, the full Mocha suite, and CodeQL semantic analysis on every push and pull request. Error handling is explicit and typed throughout: every failure raises a specific OAuthError subclass rather than a generic Error, and the library carefully distinguishes programmer/configuration errors (InvalidArgumentError) from protocol-level errors before they reach a client. File and class naming is consistently kebab-case and PascalCase respectively across lib/.

What Makes It Unique The library isn’t attempting novel protocol design — its value is being a faithful, actively maintained, framework-agnostic implementation of RFC 6749/6750/7636, continuing the project after the original oauthjs/node-oauth2-server was abandoned. Its distinguishing choices are practical rather than architectural: explicit requirePKCE/enablePlainPKCE toggles for OAuth 2.1-style enforcement, and a deliberate refusal to bundle a specific ORM or HTTP framework adapter, keeping the Model interface as the sole extension point for storage.

Used by 7 apps in this directory

TypeScript
96%
Other

Lightdash

Analytics · Data Engineering

6,119

The open-source Looker alternative that turns your dbt project's metrics and dimensions into governed, self-serve charts and dashboards — no license key required.

View details
93
Repo Health
84
Technical
64
Dependency
Built with
TypeScript96%
Updated yesterday
TypeScript
97%
Other

Outline

Knowledge Management · Collaboration

40,474

A fast, real-time collaborative knowledge base for growing teams built on React, Node.js, and ProseMirror.

View details
91
Repo Health
87
Technical
68
Dependency
Built with
TypeScript97%
Updated yesterday
JavaScript
63%
AGPL 3.0

overleaf

Collaboration · Productivity

18,090

Open-source, real-time collaborative LaTeX editor with sandboxed compilation and full TeXLive support for self-hosted academic and research teams.

View details
82
Repo Health
80
Technical
62
Dependency
Built with
JavaScript63%
TypeScript29%
Updated 1 months ago
TypeScript
91%
AGPL 3.0

PeerTube

Social Media

15,316

A federated, ActivityPub-based video hosting platform built by Framasoft — self-hostable instances interconnect into a network with no vendor lock-in, P2P-assisted streaming, and no ads.

View details
95
Repo Health
75
Technical
70
Dependency
Built with
TypeScript91%
Updated 1 weeks ago
TypeScript
97%
Other

Rocket.Chat

Team Chat

46,089

The secure, self-hosted team communications platform for organizations that cannot compromise on data sovereignty.

View details
96
Repo Health
79
Technical
66
Dependency
Built with
TypeScript97%
Updated yesterday
TypeScript
92%
Other

Hexclave

Developer Tools · Authentication

6,854

The open-source user infrastructure platform — authentication, teams, payments, emails, analytics, and more on a single unified user model.

View details
87
Repo Health
80
Technical
66
Dependency
Built with
TypeScript92%
Updated 2 days ago
JavaScript
94%
Apache 2.0

swagger-ui

Developer Tools

29,002

Transform OpenAPI specifications into interactive, browser-based API documentation that developers and consumers can explore and test live.

View details
97
Repo Health
83
Technical
65
Dependency
Built with
JavaScript94%
Updated 2 days ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search