@tsndr/cloudflare-worker-jwt
Advanced tools
Comparing version 2.5.1 to 2.5.2
/// <reference types="@cloudflare/workers-types" /> | ||
/** | ||
* @typedef JwtAlgorithm | ||
* @type {'ES256' | 'ES384' | 'ES512' | 'HS256' | 'HS384' | 'HS512' | 'RS256' | 'RS384' | 'RS512'} | ||
* @type {"ES256" | "ES384" | "ES512" | "HS256" | "HS384" | "HS512" | "RS256" | "RS384" | "RS512"} | ||
*/ | ||
export type JwtAlgorithm = 'ES256' | 'ES384' | 'ES512' | 'HS256' | 'HS384' | 'HS512' | 'RS256' | 'RS384' | 'RS512'; | ||
export type JwtAlgorithm = "ES256" | "ES384" | "ES512" | "HS256" | "HS384" | "HS512" | "RS256" | "RS384" | "RS512"; | ||
/** | ||
@@ -105,4 +105,4 @@ * @typedef JwtAlgorithms | ||
* @param {string | JsonWebKey | CryptoKey} secret A string which is used to sign the payload. | ||
* @param {JwtSignOptions | JwtAlgorithm | string} [options={ algorithm: 'HS256', header: { typ: 'JWT' } }] The options object or the algorithm. | ||
* @throws {Error} If there's a validation issue. | ||
* @param {JwtSignOptions | JwtAlgorithm | string} [options={ algorithm: "HS256", header: { typ: "JWT" } }] The options object or the algorithm. | ||
* @throws {Error} If there"s a validation issue. | ||
* @returns {Promise<string>} Returns token as a `string`. | ||
@@ -117,3 +117,3 @@ */ | ||
* @param {JWTVerifyOptions | JWTAlgorithm} options The options object or the algorithm. | ||
* @throws {Error | string} Throws an error `string` if the token is invalid or an `Error-Object` if there's a validation issue. | ||
* @throws {Error | string} Throws an error `string` if the token is invalid or an `Error-Object` if there"s a validation issue. | ||
* @returns {Promise<boolean>} Returns `true` if signature, `nbf` (if set) and `exp` (if set) are valid, otherwise returns `false`. | ||
@@ -120,0 +120,0 @@ */ |
@@ -133,5 +133,5 @@ // src/utils.ts | ||
const now = Math.floor(Date.now() / 1e3); | ||
if (payload.nbf && payload.nbf > now && Math.abs(payload.nbf - now) > (options.clockTolerance ?? 0)) | ||
if (payload.nbf && payload.nbf > now && payload.nbf - now > (options.clockTolerance ?? 0)) | ||
throw new Error("NOT_YET_VALID"); | ||
if (payload.exp && payload.exp <= now && Math.abs(payload.exp - now) > (options.clockTolerance ?? 0)) | ||
if (payload.exp && payload.exp <= now && now - payload.exp > (options.clockTolerance ?? 0)) | ||
throw new Error("EXPIRED"); | ||
@@ -138,0 +138,0 @@ const key = secret instanceof CryptoKey ? secret : await importKey(secret, algorithm, ["verify"]); |
{ | ||
"name": "@tsndr/cloudflare-worker-jwt", | ||
"version": "2.5.1", | ||
"version": "2.5.2", | ||
"description": "A lightweight JWT implementation with ZERO dependencies for Cloudflare Worker", | ||
@@ -5,0 +5,0 @@ "type": "module", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
17525