Socket
Socket
Sign inDemoInstall

@fastify/jwt

Package Overview
Dependencies
Maintainers
20
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fastify/jwt - npm Package Compare versions

Comparing version 7.2.4 to 8.0.0

7

jwt.js

@@ -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()

4

package.json
{
"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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc