该介绍目前仅提供英文版本。
Overview
cloudflare-worker-jwt is a lightweight JWT implementation with zero dependencies, made for Cloudflare Workers.
Install
npm i @tsndr/cloudflare-worker-jwt
API
sign(payload, secret, [options])— signs a payload and returns the token. Addnbfand/orexpto the payload to restrict when it is valid.verify(token, secret, [options])— checks a token’s signature and validity.decode(token)— returns a token’s header and payload without verifying it.
import jwt from "@tsndr/cloudflare-worker-jwt"
const token = await jwt.sign({ sub: "1234", exp: Math.floor(Date.now() / 1000) + 2 * 60 * 60 }, "secret")
const valid = await jwt.verify(token, "secret")