@crvouga/mockingbird-service-workos

中文文档
1.13.0发布于 2026/11/15MITTypeScriptES Module构建来源已验证近 30 天下载 1970

Stateful WorkOS AuthKit emulator with signed sessions, rotating refresh tokens and user pagination.

原始使用文档
文档目录7 节
  1. Install
  2. Usage
  3. Routes
  4. State and controls
  5. Verification
  6. Deliberately not modelled
  7. API

@crvouga/mockingbird-service-workos

Local emulators. Real API contracts. Part of Mockingbird.

WIP WorkOS AuthKit emulator: authorization redirects, single-use codes, signed JWT sessions, rotating refresh tokens, user metadata and pagination. Synthetic fixtures only.

Install

bun add -d @crvouga/mockingbird-service-workos

Usage

import { WorkOS } from "@workos-inc/node"
import { createServer } from "@crvouga/mockingbird-service-workos/server"

const server = await createServer()
const url = new URL(server.url)

// The app's own WorkOS client. Only its API host changes.
const workos = new WorkOS("mock_workos_key", {
  clientId: "client_mock",
  apiHostname: url.hostname,
  port: Number(url.port),
  https: false,
})
const authorizationUrl = workos.userManagement.getAuthorizationUrl({
  provider: "authkit",
  clientId: "client_mock",
  redirectUri: "http://localhost:3000/callback",
})

// The test stands in for the browser: the emulator signs in the seeded user and redirects with a code.
const redirect = await fetch(authorizationUrl, { redirect: "manual" })
const code = new URL(redirect.headers.get("location") ?? "").searchParams.get("code") ?? ""

const { user } = await workos.userManagement.authenticateWithCode({ code })
const { data: users } = await workos.userManagement.listUsers({ email: user.email })
console.log(users[0]?.id === user.id) // true
await server.close()

For AuthKit, set WORKOS_API_HOSTNAME/WORKOS_API_PORT from server.url and WORKOS_API_HTTPS=false, with WORKOS_API_KEY=mock_workos_key and WORKOS_CLIENT_ID=client_mock. Register your callback in the clients seed and use a local WORKOS_COOKIE_PASSWORD.

createRuntime().fetch(Request) supports in-process adapters. Raw user mirrors should use the server URL in place of https://api.workos.com. The default registered callback is http://localhost:3000/callback; authorization immediately chooses the client's seeded user. The exact @workos-inc/[email protected] and @workos-inc/[email protected] SDKs are tested over HTTP, including PKCE, JWT signature validation and expired-session refresh.

Routes

  • GET /user_management/authorize: registered callback, code, state, optional organization/PKCE.
  • POST /user_management/authenticate: client secret with authorization_code or refresh_token. A public (browser or native) client may omit client_secret and send the PKCE code_verifier instead, as AuthKit's browser SDK does; a session started that way also refreshes without a secret.
  • GET /user_management/users: bearer API key, limit/after and email filtering.
  • GET /sso/jwks/{clientId}: public ephemeral RS256 verification key used by AuthKit.

State and controls

Seed users, clients and memberships with runtime options. Options accessTtlMs, refreshTtlMs and codeTtlMs control expiry. The emulator clock controls issued timestamps. The standard /__admin/state collections expose users, clients, memberships, codes, sessions and refreshTokens. Edit sessions.revoked, expiry fields or used flags for failure scenarios. Private signing keys are ephemeral and never journaled; resetting state invalidates refresh tokens, but offline JWT verification has no revocation lookup, just like the SDK.

Standard /__admin reset, Timeline snapshots/branches, clock, faults and request journal are available. Journals store metadata, not client secrets or token request bodies. Header (x-mockingbird-namespace), path (/__admin/ns/<name>/…) and bearer credential namespaces isolate durable state. AuthKit applications should use one dedicated server per test namespace so the SDK's JWKS URL and issuer remain consistent. Configure adminPrefix to relocate the reserved tree. Presets: auth_failure, rate_limited, server_error, connection_drop; generic faults also support deterministic latency.

Verification

bun test covers acceptance, independent OpenAPI walks, deliberate divergence and both pinned SDKs. WORKOS_API_KEY=… bun run parity runs a safe list-users shape probe; it performs no account mutations and prints no user data. Missing credentials exit 2. Oracle references: authentication, users, and the pinned official SDK sources.

Deliberately not modelled

Enterprise SAML, directory synchronization, passwords, MFA, hosted AuthKit pages, logout, user mutations and webhooks. Authorization is a synthetic auto-login rather than a hosted UI. No third-party identities, network federation, exact production refresh-grace policies or distributed signing-key persistence. Error envelopes model common documented failures; vendor-specific diagnostic strings and undocumented claims are not guaranteed.

API

Root runtime exports: WorkOSAPI, WORKOS_NAMESPACE, DEFAULT_USERS, DEFAULT_CLIENTS, createRuntime, WORKOS_PRESETS, document, operationIds, supportedOperationIds. Types include WorkOSUser, WorkOSClient, Membership, WorkOSAPIOptions, WorkOSRuntimeOptions, WorkOSRuntime, OperationId, SupportedOperationId. The /server entry exports createServer, serveTarget, DEFAULT_PORT.

版本与发布记录

@crvouga/mockingbird-service-workos 共发布 20 个版本,首次发布于 2026/10/05;过去 12 个月发布了 20 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.13.0latest2026/11/151 天前
1.12.02026/11/133 天前
1.11.12026/11/123 天前
1.11.02026/11/124 天前
1.10.02026/11/114 天前
1.9.42026/11/0312 天前

关于 @crvouga/mockingbird-service-workos 的常见问题

@crvouga/mockingbird-service-workos 是什么?

Stateful WorkOS AuthKit emulator with signed sessions, rotating refresh tokens and user pagination.

如何安装 @crvouga/mockingbird-service-workos?

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

@crvouga/mockingbird-service-workos 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@crvouga/mockingbird-service-workos 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@crvouga/mockingbird-service-workos 可以商用吗?

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

@crvouga/mockingbird-service-workos 的下载量有多少?

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

@crvouga/mockingbird-service-workos 还在维护吗?

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