add algorithm to header
This commit is contained in:
15
src/index.ts
15
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)
|
||||||
|
|||||||
Reference in New Issue
Block a user