express-jwt
Advanced tools
Comparing version 7.0.0 to 7.1.0
{ | ||
"name": "express-jwt", | ||
"version": "7.0.0", | ||
"version": "7.1.0", | ||
"description": "JWT authentication middleware.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -9,3 +9,3 @@ import * as jwt from 'jsonwebtoken'; | ||
type TokenGetter = (req: express.Request) => string | undefined; | ||
type TokenGetter = (req: express.Request) => string | Promise<string> | undefined; | ||
@@ -52,3 +52,3 @@ type Params = { | ||
if (options.getToken && typeof options.getToken === 'function') { | ||
token = options.getToken(req); | ||
token = await options.getToken(req); | ||
} else if (req.headers && req.headers.authorization) { | ||
@@ -55,0 +55,0 @@ const parts = req.headers.authorization.split(' '); |
@@ -325,2 +325,26 @@ /* eslint-disable @typescript-eslint/ban-ts-comment */ | ||
it('should work with an async getToken function', function (done) { | ||
const req = {} as ExpressJwtRequest; | ||
const res = {} as express.Response; | ||
const secret = 'shhhhhh'; | ||
const token = jwt.sign({ foo: 'bar' }, secret); | ||
req.headers = {}; | ||
req.query = {}; | ||
req.query.token = token; | ||
function getTokenFromQuery(req) { | ||
return Promise.resolve(req.query.token); | ||
} | ||
expressjwt({ | ||
secret: secret, | ||
algorithms: ['HS256'], | ||
getToken: getTokenFromQuery | ||
})(req, res, function () { | ||
assert.equal(req.auth.foo, 'bar'); | ||
done(); | ||
}); | ||
}); | ||
it('should work with a secretCallback function that accepts header argument', function (done) { | ||
@@ -327,0 +351,0 @@ const req = {} as ExpressJwtRequest; |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
44711
572
0