@civic/auth-verify

中文文档
0.0.5发布于 2026/07/14TypeScriptESM + CJS近 30 天下载 4778

JWT verification library for Civic Auth

原始使用文档
文档目录10 节
  1. Features
  2. Installation
  3. Usage
  4. Basic Usage
  5. Using a Custom Cache
  6. Using a "Bundled Cache" (Pre-loaded Civic Auth JWKS)
  7. API
  8. verify(token: string, options?: VerifyOptions): Promise<JWT…
  9. Accepting multiple issuers (e.g. tenant-scoped / DCR tokens)
  10. Development

@civic/auth-verify

JWT verification library for Civic Auth tokens using JWKS endpoint discovery.

Features

  • JWT token verification using JWKS endpoint discovery
  • OIDC configuration discovery (.well-known/openid-configuration)
  • Built-in caching for JWKS data with issuer-based keys
  • Support for multiple cache implementations (InMemory and Bundled)
  • TypeScript support with full type safety

Installation

pnpm add @civic/auth-verify

Usage

Basic Usage

import { verify } from '@civic/auth-verify';

// Verify a token with default settings (uses Civic Auth issuer)
const payload = await verify(token);
console.log(payload);

Using a Custom Cache

By default, the library uses an in-memory cache for JWKS data. You can provide your own cache implementation if needed.

In the in-memory cache, keys are stored in memory and lost when the process restarts. The library uses a shared default instance across all verify calls unless you provide your own.

If you want to control the lifecycle of the cache, provide your own as follows:

import { verify, InMemoryJWKSCache } from '@civic/auth-verify';

// Create a custom cache instance
const cache = new InMemoryJWKSCache();

// Use the cache for verification
const payload = await verify(token, {
  jwksCache: cache
});

Using a "Bundled Cache" (Pre-loaded Civic Auth JWKS)

The Bundled Cache is a key cache pre-populated with Civic Auth JWKS keys, useful for offline verification or reduced latency.

  • Pre-loaded keys: Contains the latest Civic Auth JWKS bundled at build time
  • Offline support: Can verify Civic Auth tokens without any network requests
  • Performance: Eliminates the initial JWKS fetch for Civic Auth tokens
  • Updates: The bundled JWKS is updated when the package is built/published
  • Extensible: Can still fetch and cache JWKS for other issuers dynamically

Note: The bundled JWKS is specific to Civic Auth keys. If using another issuer, you can still use the InMemoryJWKSCache or implement your own cache.

import { verify, BundledJWKSCache } from '@civic/auth-verify';

// Use bundled cache with pre-downloaded Civic Auth JWKS
const cache = new BundledJWKSCache();

const payload = await verify(token, {
  jwksCache: cache
});

API

verify(token: string, options?: VerifyOptions): Promise<JWTPayload>

Verifies a JWT token and returns its payload.

Parameters

  • token - The JWT token to verify
  • options - Optional verification options
    • issuer - The token issuer URL (defaults to Civic Auth)
    • wellKnownConfigurationUrl - Custom OpenID configuration URL
    • jwksCache - Custom JWKS cache implementation
    • aud - Expected audience value for the token (optional)
    • clientId - Expected client ID value for the token (optional). If provided, the JWT must contain this value in either the client_id or tid field
    • issuerValidator - Optional predicate (issuer: string) => boolean for accepting the token's iss claim. When provided, jose's exact-match issuer check is skipped and the token's iss is validated by this function after signature verification. Use it to accept multiple issuers, e.g. tenant-scoped issuers from dynamic client registration (https://auth.civic.com/oauth/<tid>/). JWKS discovery still uses issuer (or the default), so every accepted issuer must share that JWKS.

Returns

A promise that resolves to the JWT payload.

Accepting multiple issuers (e.g. tenant-scoped / DCR tokens)

import { verify } from '@civic/auth-verify';

// Accept the base Civic issuer and any tenant-scoped issuer beneath it
const payload = await verify(token, {
  issuerValidator: (iss) => iss.startsWith('https://auth.civic.com/oauth/'),
});

Development

# Install dependencies
pnpm install

# Run tests
pnpm test

# Build
pnpm build

# Lint
pnpm lint

版本与发布记录

@civic/auth-verify 共发布 6 个版本,首次发布于 2025/06/02;过去 12 个月发布了 2 个版本。

版本发布日期距今
0.0.5latest2026/07/143 个月前
0.0.5-beta.0beta2026/07/143 个月前
0.0.42025/07/241.3 年前
0.0.32025/06/101.4 年前
0.0.2alpha2025/06/021.4 年前
0.0.12025/06/021.4 年前

关于 @civic/auth-verify 的常见问题

@civic/auth-verify 是什么?

JWT verification library for Civic Auth

如何安装 @civic/auth-verify?

在项目目录运行 npm install @civic/auth-verify,或使用 pnpm add / yarn add / bun add。

@civic/auth-verify 支持 TypeScript 吗?

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

@civic/auth-verify 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@civic/auth-verify 需要什么版本的 Node.js?

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

@civic/auth-verify 可以商用吗?

@civic/auth-verify 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@civic/auth-verify 的下载量有多少?

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

@civic/auth-verify 还在维护吗?

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