Compare commits
3 Commits
91f30929da
...
v2.4.7
| Author | SHA1 | Date | |
|---|---|---|---|
|
78554d9332
|
|||
|
dff880c02d
|
|||
|
cf24b34f63
|
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "@tsndr/cloudflare-worker-jwt",
|
"name": "@tsndr/cloudflare-worker-jwt",
|
||||||
"version": "2.4.6",
|
"version": "2.4.7",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@tsndr/cloudflare-worker-jwt",
|
"name": "@tsndr/cloudflare-worker-jwt",
|
||||||
"version": "2.4.6",
|
"version": "2.4.7",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@cloudflare/workers-types": "^4.20240208.0",
|
"@cloudflare/workers-types": "^4.20240208.0",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@tsndr/cloudflare-worker-jwt",
|
"name": "@tsndr/cloudflare-worker-jwt",
|
||||||
"version": "2.4.6",
|
"version": "2.4.7",
|
||||||
"description": "A lightweight JWT implementation with ZERO dependencies for Cloudflare Worker",
|
"description": "A lightweight JWT implementation with ZERO dependencies for Cloudflare Worker",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"exports": "./index.js",
|
"exports": "./index.js",
|
||||||
|
|||||||
16
src/index.ts
16
src/index.ts
@@ -34,6 +34,13 @@ export type JwtHeader<T = {}> = {
|
|||||||
* @default "JWT"
|
* @default "JWT"
|
||||||
*/
|
*/
|
||||||
typ?: string
|
typ?: string
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Algorithm (default: `"HS256"`)
|
||||||
|
*
|
||||||
|
* @default "HS256"
|
||||||
|
*/
|
||||||
|
alg?: JwtAlgorithm
|
||||||
} & T
|
} & T
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -196,7 +203,13 @@ export async function verify(token: string, secret: string | JsonWebKey | Crypto
|
|||||||
if (!algorithm)
|
if (!algorithm)
|
||||||
throw new Error('algorithm not found')
|
throw new Error('algorithm not found')
|
||||||
|
|
||||||
const { payload } = decode(token)
|
const { header, payload } = decode(token)
|
||||||
|
|
||||||
|
if (header?.alg !== options.algorithm) {
|
||||||
|
if (options.throwError)
|
||||||
|
throw new Error('ALG_MISMATCH')
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (!payload)
|
if (!payload)
|
||||||
@@ -214,7 +227,6 @@ export async function verify(token: string, secret: string | JsonWebKey | Crypto
|
|||||||
} catch(err) {
|
} catch(err) {
|
||||||
if (options.throwError)
|
if (options.throwError)
|
||||||
throw err
|
throw err
|
||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
3
src/test.ts
Normal file
3
src/test.ts
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
import { sign } from './index'
|
||||||
|
|
||||||
|
console.log(await sign())
|
||||||
Reference in New Issue
Block a user