@bluecateng/mock-oidc-provider

中文文档
0.4.0发布于 2026/08/12ISC构建来源已验证近 30 天下载 1744

Mock OpenID Connect server for testing

原始使用文档
文档目录15 节
  1. Usage
  2. With npx
  3. With docker
  4. Configuration
  5. Arguments
  6. Issuer
  7. Users
  8. Clients
  9. TLS
  10. Endpoints
  11. Workflows Supported
  12. Supported Claims and Scopes
  13. Known Limitations
  14. Example OIDC Client Configuration
  15. License

Mock OpenID Connect provider

ESLint CodeQL GitHub license npm version

A mock OpenID Connect provider which can be used for testing.

This provider is based on the OpenID Connect Core 1.0 specification, and inspired by OpenID Provider Mock and oauth2-mock-server. JWT and cryptography functions provided by jose.

Important security note: This mock provider is intended for development and testing only. It lacks comprehensive security features, persistent storage, and full compliance with all OpenID Connect requirements. Do not use it in production or expose it to the public internet.

  • No CSRF protection
  • No rate limiting or abuse protection
  • All sessions and tokens are stored in memory only
  • Session cookies require either localhost or HTTPS
  • Not all OIDC spec features and advanced claims are implemented

Usage

You can run the provider via npx or docker.

With npx

npx @bluecateng/mock-oidc-provider

With docker

docker run --name mock-oidc-provider --rm -p 8092:80 ghcr.io/bluecatengineering/mock-oidc-provider

Configuration

Arguments

The server can be configured either via command-line parameters or environment variables.

command lineenv vardescriptiondefault
-p, --portPORTport where the HTTP server will listen8092
-s, --tls-portTLS_PORTport where the HTTPS server will listen (when TLS is enabled)8443
-t, --ttlTTLtime to live for tokens (seconds)300
-u, --usersUSERS_FILEpath to a users YAML file
-l, --clientsCLIENTS_FILEpath to a clients YAML file
-c, --certCERT_FILETLS certificate file (see TLS section)
-k, --keyKEY_FILETLS private key file (see TLS section)
-i, --issuerISSUER_URLstatic issuer URL to use instead of the request host
-j, --jwkJWK_FILEpath to a JWK file used for signing tokens
--save-jwksave the active JWK to the given file

If --jwk is not provided, a random RSA key is generated automatically. Use --save-jwk <file> to write the active JWK (whether generated or loaded) to a JSON file for later reuse.

Issuer

The issuer is the value of the issuer field in the discovery document and of the iss claim in every token. It also determines the endpoint URLs published in the discovery document, so that they always agree with each other.

If --issuer is not provided, the issuer is derived from each request as <protocol>://<host>/ (ending in / for Auth0 compatibility). A value passed to --issuer is used verbatim.

Behind a reverse proxy

The X-Forwarded-Proto and X-Forwarded-Host headers are honored, so a provider running behind a TLS-terminating proxy advertises the external https:// URLs rather than the internal ones it is reached at:

issuer                 https://auth.example.com/
authorization_endpoint https://auth.example.com/authorize

These headers are accepted from any client, which means a caller can influence the advertised URLs. Set --issuer to pin the issuer to a fixed value regardless of the incoming headers.

Users

By default, two users are provided (foo and bar). If a users file is supplied, it replaces the default users.

Users file format (YAML):

  • The top-level value must be an array.
  • Each array entry must be an object containing:
    • sub (string): the subject identifier.
    • Optional additional claims to be included in both the access and the ID tokens.
    • Optional idClaims: included only in ID tokens.
    • Optional accessClaims: included only in access tokens.

Example

- sub: eeny
  email: [email protected]
  idClaims:
    name: Eeny
  accessClaims:
    mock: a
- sub: meeny
  email: [email protected]
  idClaims:
    name: Meeny
  accessClaims:
    mock: b
- sub: miny
  email: [email protected]
  idClaims:
    name: Miny
  accessClaims:
    mock: c

Clients

By default, one client is provided (baz). If a clients file is supplied, it replaces the default clients.

Clients file format (YAML):

  • The top-level value must be an array.
  • Each array entry must be an object containing:
    • sub (string): the client identifier.
    • Optional additional claims to be included in access tokens.

Example

- sub: service-a
  role: machine
- sub: service-b
  team: platform

TLS

To enable HTTPS, specify both:

  • --cert <file>
  • --key <file>

These files are passed directly to https.createServer.

When TLS is enabled:

  • An HTTP server always runs on --port (default: 8092).
  • An HTTPS server also runs on --tls-port (default: 8443).

If TLS is not enabled (no cert/key specified), only the HTTP server runs.

Endpoints

The discovery document (/.well-known/openid-configuration) exposes all supported endpoints.

Main endpoints:

  • /.well-known/openid-configuration — OIDC discovery metadata
  • /.well-known/jwks.json — JWKS for token validation
  • /authorize — Authorization endpoint
  • /oauth/token — Token endpoint
  • /oauth/revoke — Token revocation
  • /oidc/logout — End session
  • /userinfo — UserInfo endpoint
  • /introspect — Token introspection
  • /api/clear — Testing utility: clears all sessions and authorization codes

Workflows Supported

  • Authorization Code Flow
  • Authorization Code Flow with PKCE
  • Client Credentials Flow
  • Resource Owner Password Flow

The Implicit Flow is not supported.

Supported Claims and Scopes

  • All user object properties appear in both access and ID tokens except:
    • idClaims: ID token only
    • accessClaims: access token only
  • /userinfo returns all user claims; scope is not enforced.
  • Standard OIDC scopes (openid, profile, email) are accepted but not strictly validated.

Known Limitations

  • Not production-ready.
  • Not fully OIDC-compliant.
  • All state is stored in memory.
  • No CSRF protection, no rate limiting.
  • Minimal validation of client authentication.
  • Should only be used in local development or CI environments.

Example OIDC Client Configuration

Discovery URL:

http://localhost:8092/.well-known/openid-configuration

Client configuration:

  • Client ID: any string (client authentication is not enforced)
  • Redirect URI: must match the value passed to /authorize
  • Scopes: openid profile email or as needed
  • Response type: code

License

ISC

版本与发布记录

@bluecateng/mock-oidc-provider 共发布 9 个版本,首次发布于 2025/07/05;过去 12 个月发布了 7 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.4.0latest2026/08/122 个月前
0.3.42026/04/017 个月前
0.3.32026/03/317 个月前
0.3.22026/03/317 个月前
0.3.12026/03/317 个月前
0.3.02025/12/0611 个月前

关于 @bluecateng/mock-oidc-provider 的常见问题

@bluecateng/mock-oidc-provider 是什么?

Mock OpenID Connect server for testing

如何安装 @bluecateng/mock-oidc-provider?

在项目目录运行 npm install @bluecateng/mock-oidc-provider,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 mock-oidc-provider,可以用 npx mock-oidc-provider 直接运行。

@bluecateng/mock-oidc-provider 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/bluecateng__mock-oidc-provider 是否存在。

@bluecateng/mock-oidc-provider 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@bluecateng/mock-oidc-provider 可以商用吗?

@bluecateng/mock-oidc-provider 使用 ISC 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@bluecateng/mock-oidc-provider 的下载量有多少?

根据 npm 官方下载统计,@bluecateng/mock-oidc-provider 在 2026/10/09 – 2026/11/07 这 30 天内被下载 1,744 次,日均约 58 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@bluecateng/mock-oidc-provider 还在维护吗?

最新版本 0.4.0 发布于 2026/08/12(2 个月前);至今共发布 9 个版本,其中过去 12 个月发布了 7 个;首次发布于 2025/07/05。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。