由 Opal W. 出售

A fully certified OAuth 2.0 and OpenID Connect authorization server for Node.js, supporting PKCE, DPoP, FAPI, CIBA, PAR, and more. Mountable into Express, Koa, Fastify, Hapi, and NestJS applications.
This block delivers a production-grade OAuth 2.0 Authorization Server with full OpenID Connect support, including device flow, PKCE, PAR, DPoP, CIBA, FAPI profiles, dynamic client registration, and JWT/opaque access tokens. It is intended for backend engineers embedding an OIDC IdP into a Node.js service that needs to issue and validate tokens for first- or third-party clients.
index.js - Public entry point; re-exports Provider, errors, interactionPolicy, and ExternalSigningKey.provider.js - Core Provider class: constructs the Koa app, mounts all routes, owns configuration.actions/ - Koa middleware stacks for every endpoint (authorization, token, userinfo, introspection, revocation, JWKS, discovery, end-session, device, CIBA, PAR, registration).actions/authorization/ - Fine-grained middleware pipeline for the authorization endpoint (50+ discrete steps).actions/grants/ - Grant-type handlers: authorization_code, client_credentials, refresh_token, device_code, ciba.adapters/ - Storage adapter interface; ships a built-in in-memory adapter (memory_adapter.js).consts/ - Shared constants: parameter lists, JWA algorithm sets, client attribute schemas, dev keystore.helpers/ - Internal utilities: error classes, interaction policy, weak-cache, keystore, attention warnings.models/ - Token model definitions (AccessToken, AuthorizationCode, RefreshToken, etc.).response_modes/ - Response mode implementations (query, fragment, form_post, JARM).shared/ - Reusable Koa middleware (body parsing, session, duplicate-param rejection, resource checks).views/ - ETA templates for built-in HTML pages (interaction, device, error).npm install koa @koa/router @koa/cors jose nanoid quick-lru raw-body debug eta jsesc
No native modules, no pod install, no Android linking steps required. Node.js v22 LTS or later is mandatory (the library emits a warning and may behave incorrectly on older runtimes).
启动隔离沙箱并在服务器端直接运行 — 无需本地配置。
此版本的 Tetrees AI Review
This Express backend / api completed archive review. Structure, dependency manifests, documentation, functional source, and common risk patterns were checked by the Tetrees verification pipeline; runtime phases are stated separately.
Deterministic AVCP artifact review
管道 avcp-2026-08-04.1 · SHA-256 13661dfa1d2fd50e…
This version-scoped review deterministically inspects the submitted archive for structure, dependencies, documentation, functional source, and common malicious or high-risk signals. Build and test phases are reported as passed only after an isolated sandbox audition. It is not a guarantee of perfect security.
审查日期 2026年8月4日
将此产品直接导入你的 AI IDE、网页构建器或云端 IDE。
将 Tetrees 连接到兼容的 AI IDE,列出你拥有的产品并获取已验证 ZIP,同时不会开放卖家上传权限。
暂无评价。
Sign in to join the discussion
Loading discussion…
Copy source: Place the source/ directory into your project, e.g. src/oidc/.
ESM only: oidc-provider is pure ESM. Ensure "type": "module" in your package.json, or rename files to .mjs. TypeScript users set "module": "ESNext" and "moduleResolution": "bundler" (or "node16") in tsconfig.json.
tsconfig paths (TypeScript only):
{
"compilerOptions": {
"module": "ESNext",
"moduleResolution": "bundler",
"paths": {
"oidc-provider": ["./src/oidc/index.js"]
}
}
}
Adapter: Implement the eight-method adapter interface (find, upsert, consume, destroy, findByUserCode, findByUid, revokeByGrantId, connect) and pass the class to Provider configuration. The in-memory adapter at adapters/memory_adapter.js works for development.
Environment variables (minimum set):
ISSUER=https://auth.example.com
JWKS_JSON=[{"kty":"RSA",...}] # JSON array of private JWK objects
Mount: Call provider.callback() to get a Node.js http.RequestListener and attach it to Express/Koa/native http.createServer.
import Provider from './src/oidc/index.js';
const provider = new Provider(issuer: string, configuration: Configuration): Provider;
// provider.callback() → http.RequestListener (attach to express/koa/http)
// provider.app → underlying Koa application
The main class. Pass your issuer URL and a configuration object covering clients, jwks, adapter, features, ttl, scopes, claims, and interaction hooks. Mount provider.callback() on any Node.js HTTP framework.
import { errors } from './src/oidc/index.js';
errors.InvalidClient // extends OIDCProviderError
errors.AccessDenied
errors.InvalidRequest
errors.InteractionRequired
// …and ~30 more named error classes
Throw these inside custom interaction routes, adapter methods, or findAccount to signal structured OAuth error responses back to clients. Each class sets the correct error and error_description fields automatically.
import { interactionPolicy } from './src/oidc/index.js';
const { base, Prompt, Check } = interactionPolicy;
// base() → default policy array [login prompt, consent prompt]
// new Prompt(name, ...checks)
// new Check(reason, description, fn)
Use interactionPolicy to define when the provider should redirect users to your login/consent UI. Replace or extend the default base() policy with custom Prompt and Check instances.
import { ExternalSigningKey } from './src/oidc/index.js';
new ExternalSigningKey({ kid: string, alg: string, key: KeyLike | CryptoKey })
Pass an ExternalSigningKey instance inside the jwks configuration when your private signing key is stored in an HSM, KMS, or is otherwise not directly exportable. The provider delegates signing to the key object without ever holding the raw private key bytes.
A quick local development server that serves all OIDC endpoints with a single hardcoded client.
import http from 'node:http';
import Provider from './src/oidc/index.js';
import MemoryAdapter from './src/oidc/adapters/memory_adapter.js';
const provider = new Provider('http://localhost:3000', {
adapter: MemoryAdapter,
clients: [
{
client_id: 'app',
client_secret: 'secret',
redirect_uris: ['http://localhost:8080/cb'],
grant_types: ['authorization_code', 'refresh_token'],
response_types: ['code'],
},
],
jwks: {
keys: [
// paste a private RSA or EC JWK here
],
},
scopes: ['openid', 'profile', 'email', 'offline_access'],
async findAccount(_ctx, id) {
return {
accountId: id,
async claims() { return { sub: id, email: `${id}@example.com` }; },
};
},
});
http.createServer(provider.callback()).listen(3000, () => {
console.log('OIDC provider listening on http://localhost:3000');
console.log('Discovery: http://localhost:3000/.well-known/openid-configuration');
});
Override the default interaction policy to always require a fresh login, ignoring existing sessions.
import Provider from './src/oidc/index.js';
import { interactionPolicy } from './src/oidc/index.js';
const { base, Check } = interactionPolicy;
const policy = base();
const loginPrompt = policy.get('login');
loginPrompt.checks.add(
new Check(
'session_expired',
'End-User session is too old; re-authentication required.',
(ctx) => {
const { oidc } = ctx;
if (oidc.session?.accountId) {
const age = (Date.now() / 1000) - oidc.session.loginTs;
if (age > 900) return Check.REQUEST_PROMPT; // 15-minute max session age
}
return Check.NO_NEED_TO_PROMPT;
},
),
);
const provider = new Provider('https://auth.example.com', {
interactions: { policy },
// …other config
});
Use the errors namespace inside adapter or custom logic to produce well-formed OAuth error responses.
import { errors } from './src/oidc/index.js';
async function findAccount(ctx, sub) {
const user = await db.users.findOne({ sub });
if (!user) {
throw new errors.InvalidRequest('account not found');
}
if (user.suspended) {
throw new errors.AccessDenied('account is suspended', 403);
}
return {
accountId: user.sub,
async claims(use, scope) {
return { sub: user.sub, email: user.email };
},
};
}
index.js - Re-exports Provider, errors, interactionPolicy, ExternalSigningKey; performs runtime version check.provider.js - Instantiates and configures the Koa app; registers all route stacks from actions/.actions/index.js - Aggregates and exports all endpoint factory functions used by provider.js.actions/authorization/index.js - Composes the 50+ step middleware pipeline for /auth, /device_authorization, PAR, and resume endpoints.actions/grants/index.js - Named exports for each grant type handler; consumed by actions/token.js.adapters/memory_adapter.js - Reference in-memory adapter; not suitable for production or multi-process deployments.consts/index.js - Exports PARAM_LIST, PUSHED_REQUEST_URN, CLIENT_ATTRIBUTES, DEV_KEYSTORE, JWA.helpers/ - Internal error classes, interaction policy constructors, weak-cache for per-provider state, keystore helpers.models/ - Token lifecycle models (mint, find, consume, destroy) used by grant handlers.response_modes/ - Pluggable response mode implementations written as Koa middleware.shared/ - Generic middleware (session loading, body parsing, resource indicator checks, duplicate param rejection).views/ - ETA HTML templates for built-in fallback UI pages; override by providing renderError and interaction redirects.require() of this source will throw ERR_REQUIRE_ESM. Fix: add "type": "module" to package.json or use dynamic import() inside an async wrapper.node:22 (or the node:lts Docker tag).jwks configuration: The provider will refuse to start or fail to sign tokens. Fix: always supply at least one private RSA (RS256) or EC (ES256) JWK in configuration.jwks.keys.provider.interactionFinished with an incorrect result shape, the user gets an infinite redirect loop. Fix: return { login: { accountId: string } } for login and { consent: { rejectedScopes: [], rejectedClaims: [] } } for consent.code_challenge will receive invalid_request. Fix: either pass code_challenge_method and code_challenge in the authorization request, or explicitly configure features.pkce.required to return false for your client type.I have the oidc-provider library source code located at `src/oidc/` in my project.
A usage guide is in `USAGE.md`. The upstream package is `user@example.com` (ESM only, Node.js v22+ required).
Please help me integrate this into my existing Express/Node.js project step by step:
1. Read `USAGE.md` and `src/oidc/index.js` to understand available exports.
2. Create `src/oidc-config.js` that instantiates a `Provider` using the real `Provider` export,
wires my existing database as an adapter (8-method interface), configures `jwks` from
the `JWKS_JSON` env var, and exports the provider instance.
3. Mount the provider on my Express app using `provider.callback()` under the path `/oidc`.
4. Add a `/interaction/:uid` route that reads the current interaction with
`provider.interactionDetails(req, res)` and calls `provider.interactionFinished` after login.
5. Use `errors.InvalidRequest` and `errors.AccessDenied` from `src/oidc/index.js` for
structured error responses in my findAccount implementation.
6. Do not invent any APIs; only use symbols documented in USAGE.md and visible in src/oidc/index.js.
oidc-provider is licensed under the MIT License. See source/LICENSE if present, or refer to the npm package page and the upstream repository maintained by Filip Skokan.
This product’s unique contribution is clean room implementation of valuable code block into AVCP compatible standard.
完整安装指南与集成提示词将在购买后解锁。
Automation, Utilities & Developer Tools
免费