@fastify/jwt
Advanced tools
Comparing version 7.2.4 to 8.0.0
@@ -243,11 +243,6 @@ 'use strict' | ||
} | ||
} else if ((request.headers && request.headers.authorization) && (!onlyCookie)) { | ||
} else if (request.headers.authorization && !onlyCookie && /^Bearer\s/i.test(request.headers.authorization)) { | ||
const parts = request.headers.authorization.split(' ') | ||
if (parts.length === 2) { | ||
const scheme = parts[0] | ||
token = parts[1] | ||
if (!/^Bearer$/i.test(scheme)) { | ||
throw new BadRequestError() | ||
} | ||
} else { | ||
@@ -254,0 +249,0 @@ throw new BadRequestError() |
{ | ||
"name": "@fastify/jwt", | ||
"version": "7.2.4", | ||
"version": "8.0.0", | ||
"description": "JWT utils for Fastify", | ||
@@ -48,3 +48,3 @@ "main": "jwt.js", | ||
"tap": "^16.0.0", | ||
"tsd": "^0.29.0" | ||
"tsd": "^0.30.0" | ||
}, | ||
@@ -51,0 +51,0 @@ "publishConfig": { |
@@ -472,2 +472,32 @@ # @fastify/jwt | ||
### `extractToken` | ||
Setting this option will allow you to extract a token using function passed in for `extractToken` option. The function definition should be `(request: FastifyRequest) => token`. Fastify JWT will check if this option is set, if this option is set it will use the function defined in the option. When this option is not set then it will follow the normal flow. | ||
```js | ||
const fastify = require('fastify') | ||
const jwt = require('@fastify/jwt') | ||
fastify.register(jwt, { secret: 'test', verify: { extractToken: (request) => request.headers.customauthheader } }) | ||
fastify.post('/sign', function (request, reply) { | ||
return reply.jwtSign(request.body) | ||
.then(function (token) { | ||
return { token } | ||
}) | ||
}) | ||
fastify.get('/verify', function (request, reply) { | ||
// token avaiable via `request.headers.customauthheader` as defined in fastify.register above | ||
return request.jwtVerify() | ||
.then(function (decodedToken) { | ||
return reply.send(decodedToken) | ||
}) | ||
}) | ||
fastify.listen(3000, function (err) { | ||
if (err) throw err | ||
}) | ||
``` | ||
#### Typescript | ||
@@ -474,0 +504,0 @@ |
Sorry, the diff of this file is too big to display
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
166996
918
3805