express-openid-connect は Express アプリにログイン機能を追加するためのクライアント側ミドルウェアです。一方、oidc-provider は独自の認証サーバーを構築するためのサーバー側ライブラリです。この 2 つは補完的な関係にあり、同じ問題を解決する競合他社ではありません。開発者が直面する本当の選択は、「既存の認証サービスを使うか」それとも「自前で認証サーバーを作るか」という архитектур 上の決定です。
express-openid-connect と oidc-provider は、どちらも Node.js エコシステムで OpenID Connect プロトコルを扱いますが、全く異なる役割を果たします。前者はアプリにログイン機能を追加する「利用者側」のツールであり、後者は認証サーバーそのものを作る「提供者側」のツールです。この根本的な違いを理解しないと、アーキテクチャ設計で重大なミスを犯す可能性があります。
express-openid-connect は、既存の Identity Provider (IdP) に対してクライアントとして動作します。
// express-openid-connect: クライアント側の実装
const { auth, requiresAuth } = require('express-openid-connect');
const config = {
authRequired: false,
auth0: {
domain: 'YOUR_DOMAIN',
clientId: 'YOUR_CLIENT_ID',
clientSecret: 'YOUR_CLIENT_SECRET'
},
baseURL: 'http://localhost:3000',
secret: 'LONG_RANDOM_STRING'
};
app.use(auth(config));
app.get('/profile', requiresAuth(), (req, res) => {
res.send(req.oidc.user);
});
oidc-provider は、あなたが Identity Provider になるためのサーバー実装です。
// oidc-provider: サーバー側の実装
const Provider = require('oidc-provider');
const provider = new Provider('http://localhost:3000', {
clients: [
{
client_id: 'client-id',
client_secret: 'client-secret',
redirect_uris: ['http://localhost:3000/callback']
}
],
interactions: {
url: '/interaction' // カスタムログイン画面へのパス
}
});
app.use(provider.callback);
express-openid-connect は設定オブジェクトを渡すだけで動作します。
// express-openid-connect: シンプルな設定
const config = {
auth0: {
domain: 'tenant.auth0.com',
clientId: 'client-id'
},
secret: 'session-secret' // セッション暗号化用
};
// これだけでログイン・ログアウト・プロフィール取得が有効化されます
app.use(auth(config));
oidc-provider はサーバーの挙動を細かく定義する必要があります。
// oidc-provider: 詳細な設定
const config = {
features: {
encryption: { enabled: true },
jwtUserinfo: { enabled: true }
},
cookies: {
names: {
session: 'oidc.session',
interaction: 'oidc.interaction'
}
},
// ユーザー検証ロジックも自前で実装する必要があります
async findAccount(ctx, id) {
return { accountId: id };
}
};
const provider = new Provider('http://localhost:3000', config);
express-openid-connect はセッション管理を自動で行います。
// express-openid-connect: セッションは自動管理
app.get('/dashboard', requiresAuth(), (req, res) => {
// req.oidc.isAuthenticated() でログイン状態を確認
// req.oidc.user でユーザー情報を取得
// セッション有効期限の更新も自動です
res.render('dashboard', { user: req.oidc.user });
});
oidc-provider は UI フローを自分で構築します。
/interaction エンドポイントなどでログインフォームを表示します。// oidc-provider: UI 連携は自前
app.get('/interaction', async (req, res) => {
const { uid, prompt, details } = await provider.interactionDetails(req, res);
// ここで独自のログインフォームをレンダリングします
res.render('login', { uid, prompt });
});
// 認証完了後に provider に結果を返します
app.post('/interaction', async (req, res) => {
const result = { login: { accountId: 'user123' } };
await provider.interactionFinished(req, res, result);
});
express-openid-connect は Auth0 によって维护されています。
// express-openid-connect: ベンダー依存の例
// Auth0 固有の機能拡張が使えますが、他プロバイダーでは動かない場合があります
const config = {
auth0: {
domain: 'specific-tenant.auth0.com' // 特定のテナントに依存
}
};
oidc-provider はコミュニティと維持者によって支えられています。
// oidc-provider: 自前維持の例
// 設定変更やアップデートはすべて自分の責任で行います
const provider = new Provider('http://localhost:3000', {
// セキュリティ設定も自分で管理します
jwks: { keys: [/* 自分で管理する鍵 */] }
});
両者は役割が違いますが、同じプロトコル標準に従っています。
// 両者とも標準的な OIDC フローを使用します
// express-openid-connect: 自動的に標準フローを実行
// oidc-provider: 標準フローを受け付けて処理する
// express-openid-connect: トークンを自動検証
const user = req.oidc.user; // ID トークンから抽出
// oidc-provider: トークンを発行
// 内部で JWT 署名を行い、クライアントに返却します
// 両者とも app.use() で導入可能
app.use(auth(config)); // express-openid-connect
app.use(provider.callback); // oidc-provider
| 特徴 | express-openid-connect | oidc-provider |
|---|---|---|
| 役割 | 🧑💻 クライアント (RP) | 🏢 サーバー (OP) |
| 目的 | ログイン機能の追加 | 認証サーバーの構築 |
| 設定 | 🟢 簡単 (数分) | 🔴 複雑 (数週間) |
| UI 責任 | ❌ 外部プロバイダー | ✅ 自前実装 |
| 保守 | 🟢 ベンダー管理 | 🟡 自前管理 |
| 向いている案件 | 社内ツール、SaaS、スタートアップ | 金融、大手プラットフォーム、特殊要件 |
express-openid-connect は、認証そのものがビジネスのコアではない場合に最適です 🧰。ログイン機能を素早く実装し、セキュリティの負担を外部に任せたいプロジェクトに向いています。大多数の Web アプリケーションはこちらを選ぶべきです。
oidc-provider は、認証サービスそのものが製品である場合に最適です 🔧。ユーザーデータを自社で完全に管理し、他社に認証機能を提供したい場合にのみ選択してください。维护コストを十分に見積もった上で導入する必要があります。
重要な注意点: この 2 つは競合ではなく、組み合わせることも可能です。oidc-provider で自前の認証サーバーを作り、express-openid-connect でそのサーバーを使ってアプリにログインさせる構成も技術的に成立します。しかし、多くの場合、既存のマネージドサービスを使う方がコスト効率が良くなります。
自社で認証サーバーをゼロから構築し、他のアプリにトークンを発行したい場合に選択します。ログイン画面のデザインや認証フローを完全に制御できます。技術的な負担は大きいですが、データ主权やカスタム要件を満たす必要がある場合に最適です。
既存の認証プロバイダーを使って Express アプリにログイン機能を追加したい場合に選択します。設定が簡単で、セッション管理やトークンの更新を自動で行います。Auth0 などのサービスと連携する際に最も適しており、認証ロジックを自前で維持する負担を減らせます。
This module provides an OAuth 2.0 (RFC 6749) Authorization Server with support for OpenID Connect (OIDC) and many other additional features and standards.
Table of Contents
The following specifications are implemented by oidc-provider (not exhaustive):
Note that not all features are enabled by default, check the configuration section on how to enable them.
RFC6749 - OAuth 2.0 & OIDC Core 1.0Discovery 1.0 & RFC8414 Authorization Server MetadataRP-Initiated Logout 1.0Back-Channel Logout 1.0RFC7009 - OAuth 2.0 Token RevocationRFC7636 - Proof Key for Code Exchange (PKCE)RFC7662 - OAuth 2.0 Token IntrospectionRFC8252 - OAuth 2.0 for Native Apps BCP (AppAuth)RFC8628 - OAuth 2.0 Device Authorization Grant (Device Flow)RFC8705 - OAuth 2.0 Mutual TLS Client Authentication and Certificate Bound Access Tokens (MTLS)RFC8707 - OAuth 2.0 Resource IndicatorsRFC9101 - OAuth 2.0 JWT-Secured Authorization Request (JAR)RFC9126 - OAuth 2.0 Pushed Authorization Requests (PAR)RFC9207 - OAuth 2.0 Authorization Server Issuer Identifier in Authorization ResponseRFC9449 - OAuth 2.0 Demonstration of Proof-of-Possession at the Application Layer (DPoP)RFC9701 - JWT Response for OAuth Token IntrospectionFAPI 1.0)FAPI 2.0)FAPI 2.0)JARM)CIBA)Supported Access Token formats:
The following specifications and drafts are implemented as experimental features:
FAPI-CIBA) - Implementers Draft 01CIMD) - Draft 01Updates to experimental feature specification versions are released as MINOR library versions,
if you utilize these features consider using the tilde ~ operator in your
package.json since breaking changes may be introduced as part of these version updates. Alternatively
acknowledge the version and be notified of breaking changes as part of
your CI.

Filip Skokan has certified that oidc-provider
conforms to the following profiles of the OpenID Connect™ protocol.
If you want to quickly add OpenID Connect authentication to Node.js apps, feel free to check out Auth0's Node.js SDK and free plan. Create an Auth0 account; it's free!
If you or your company use this module, or you need help using/upgrading the module, please consider becoming a sponsor so I can continue maintaining it and adding new features carefree. The only way to guarantee you get feedback from the author & sole maintainer of this module is to support the package through GitHub Sponsors.
oidc-provider can be mounted to existing connect, express, fastify, hapi, or koa applications, see how. The authorization server allows to be extended and configured in various ways to fit a variety of uses. See the documentation and example folder.
import * as oidc from "oidc-provider";
const provider = new oidc.Provider("http://localhost:3000", {
// refer to the documentation for other available configuration
clients: [
{
client_id: "foo",
client_secret: "bar",
redirect_uris: ["http://localhost:8080/cb"],
// ... other client properties
},
],
});
const server = provider.listen(3000, () => {
console.log(
"oidc-provider listening on port 3000, check http://localhost:3000/.well-known/openid-configuration",
);
});
External type definitions are available via DefinitelyTyped.
Collection of Community-maintained configuration use cases are in the Community Guides Discussions section
oidc-provider instances are event emitters, using event handlers you can hook into the various actions and i.e. emit metrics that react to specific triggers. See the list of available emitted event names and their description.
| Version | Security Fixes 🔑 | Other Bug Fixes 🐞 | New Features ⭐ |
|---|---|---|---|
| v9.x | Security Policy | ✅ | ✅ |
| v8.x | Security Policy | ❌ | ❌ |