@tsndr/cloudflare-worker-jwt
Advanced tools
Comparing version 2.2.2 to 2.2.3
@@ -75,2 +75,6 @@ /// <reference types="@cloudflare/workers-types" /> | ||
/** | ||
* If `true` all expiry checks will be skipped | ||
*/ | ||
skipValidation?: boolean; | ||
/** | ||
* If `true` throw error if checks fail. (default: `false`) | ||
@@ -77,0 +81,0 @@ * |
10
index.js
@@ -111,6 +111,6 @@ "use strict"; | ||
*/ | ||
async function verify(token, secret, options = { algorithm: 'HS256', throwError: false }) { | ||
async function verify(token, secret, options = { algorithm: 'HS256', skipValidation: false, throwError: false }) { | ||
if (typeof options === 'string') | ||
options = { algorithm: options, throwError: false }; | ||
options = { algorithm: 'HS256', throwError: false, ...options }; | ||
options = { algorithm: 'HS256', skipValidation: false, throwError: false, ...options }; | ||
if (typeof token !== 'string') | ||
@@ -129,3 +129,3 @@ throw new Error('token must be a string'); | ||
const { payload } = decode(token); | ||
if (!payload) { | ||
if (!options.skipValidation && !payload) { | ||
if (options.throwError) | ||
@@ -135,3 +135,3 @@ throw 'PARSE_ERROR'; | ||
} | ||
if (payload.nbf && payload.nbf > Math.floor(Date.now() / 1000)) { | ||
if (!options.skipValidation && payload.nbf && payload.nbf > Math.floor(Date.now() / 1000)) { | ||
if (options.throwError) | ||
@@ -141,3 +141,3 @@ throw 'NOT_YET_VALID'; | ||
} | ||
if (payload.exp && payload.exp <= Math.floor(Date.now() / 1000)) { | ||
if (!options.skipValidation && payload.exp && payload.exp <= Math.floor(Date.now() / 1000)) { | ||
if (options.throwError) | ||
@@ -144,0 +144,0 @@ throw 'EXPIRED'; |
{ | ||
"name": "@tsndr/cloudflare-worker-jwt", | ||
"version": "2.2.2", | ||
"version": "2.2.3", | ||
"description": "A lightweight JWT implementation with ZERO dependencies for Cloudflare Worker", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -107,3 +107,3 @@ # Cloudflare Worker JWT | ||
`secret` | `string` | required | - | The string which was used to sign the payload. | ||
`options` | `object` | optional | `{ algorithm: 'HS256', throwError: false }` | The options object supporting `algorithm` and `throwError`. (See [Available Algorithms](#available-algorithms)) | ||
`options` | `object` | optional | `{ algorithm: 'HS256', skipValidation: false, throwError: false }` | The options object supporting `algorithm`, `skipValidation` and `throwError`. (See [Available Algorithms](#available-algorithms)) | ||
@@ -110,0 +110,0 @@ #### `throws` |
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
17765
6
302