@clerk/backend-core

中文文档
2.13.2发布于 2023/01/20MITES Module近 30 天下载 8826

Clerk Backend API core resources and authentication utilities for JavaScript environments.

此软件包已被标记为弃用

This package has been deprecated - use @clerk/backend instead

原始使用文档
文档目录14 节
  1. Overview
  2. Getting Started
  3. Installation
  4. Build
  5. Architecture
  6. How it works
  7. Usage
  8. Creating a Base for a new SDK
  9. Validate the Authorized Party of a session token
  10. Clerk API Resources
  11. Support
  12. Contributing
  13. Security
  14. License


@clerk/backend-core


Deprecation warning

This package has been deprecated in favor of the isomorphic @clerk/backend which is now used across all server-enabled Clerk packages. This package will not receive any future updates. It should not be used directly - please use as a reference only.

Overview

This package provides Clerk Backend API core resources and low-level authentication utilities for JavaScript environments. It is mostly used as the base for other Clerk SDKs.

Getting Started

Installation

npm install @clerk/backend-core

Build

To build the package locally with the TypeScript compiler, run:

npm run build

Architecture

@clerk/backend-core contains all the logic for basic Clerk functionalities, without being platform/environment, specific such as:

  • Determining the authentication state of a session.
  • Validating a Clerk token state.
  • Clerk API resource management.

How it works

This package is used as the base building block for Clerk JavaScript SDKs and environments. This is achieved by providing all the required business logic if only a few environment-specific utilities are implemented by the client.


In essence, the client should supply these key functions in the Clerk Base and ClerkBackendApi classes:

  1. Public key import importKeyFunction.
  2. JWT signature verification verifySignatureFunction.
  3. Base64 decoding decodeBase64Function.
  4. HTTP fetching utility for the API resource management ClerkFetcher.

After supplying those in the Base and ClerkBackendApi classes, you can use all the Clerk utilities required for the SDK business logic.

Usage

Creating a Base for a new SDK

const importKey = async (jwk: JsonWebKey, algorithm: Algorithm) => {
  //  ...
};

const verifySignature = async (algorithm: Algorithm, key: CryptoKey, signature: Uint8Array, data: Uint8Array) => {
  // ...
};

const decodeBase64 = (base64: string) => {
  // ...
};

/** Base initialization */
const examplePlatformBase = new Base(importKey, verifySignature, decodeBase64);

After creating the Base instance you can use core functions such as:

examplePlatformBase.verifySessionToken(...);

examplePlatformBase.getAuthState(...);

The Base utilities include the building blocks for developing any extra logic and middleware required for the target platform.

Validate the Authorized Party of a session token

Clerk's JWT session token, contains the azp claim, which equals the Origin of the request during token generation. You can provide a list of whitelisted origins to verify against, during every token verification, to protect your application of the subdomain cookie leaking attack. You can find an example below:

const authorizedParties = ['http://localhost:3000', 'https://example.com'];

examplePlatformBase.verifySessionToken(token > { authorizedParties });

Clerk API Resources

API resource management is also provided by this package through the ClerkBackendApi class. For more information on the API resources you can checkout the resource documentation page.

To use the Clerk Backend API wrapper in any JavaScript platform, you would need to provide some specific SDK information and an HTTP fetching utility. See more at the ClerkBackendAPIProps implementation.

Support

You can get in touch with us in any of the following ways:

Contributing

We're open to all community contributions! If you'd like to contribute in any way, please read our contribution guidelines.

Security

@clerk/backend-core follows good practices of security, but 100% security cannot be assured.

@clerk/backend-core is provided "as is" without any warranty. Use at your own risk.

For more information and to report security issues, please refer to our security documentation.

License

This project is licensed under the MIT license.

See LICENSE for more information.

版本与发布记录

@clerk/backend-core 共发布 228 个版本,首次发布于 2022/01/20;过去 12 个月发布了 0 个版本。

版本发布日期距今
2.13.2latest2023/01/203 年前
2.13.12023/01/193 年前
2.13.02023/01/173 年前
2.12.22023/01/123 年前
2.13.0-staging.1staging2023/01/113 年前
2.13.0-staging.02023/01/093 年前

其他发布通道:prerelease → 0.1.0-alpha.3,next → 2.9.3-next.2,staging → 2.13.0-staging.1。

关于 @clerk/backend-core 的常见问题

@clerk/backend-core 是什么?

Clerk Backend API core resources and authentication utilities for JavaScript environments.注意:该包已被作者标记为弃用——This package has been deprecated - use @clerk/backend instead

如何安装 @clerk/backend-core?

在项目目录运行 npm install @clerk/backend-core,或使用 pnpm add / yarn add / bun add。

@clerk/backend-core 支持 TypeScript 吗?

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

@clerk/backend-core 支持 ESM 还是 CommonJS?

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

@clerk/backend-core 需要什么版本的 Node.js?

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

@clerk/backend-core 可以商用吗?

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

@clerk/backend-core 的下载量有多少?

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

@clerk/backend-core 还在维护吗?

最新版本 2.13.2 发布于 2023/01/20(3 年前);至今共发布 228 个版本,其中过去 12 个月发布了 0 个;首次发布于 2022/01/20。作者已将其标记为弃用,新项目建议寻找替代方案。