Skip to content

Commit b71829a

Browse files
authored
docs: update references to old fastify-* modules (#223)
1 parent 01d74e6 commit b71829a

File tree

3 files changed

+31
-31
lines changed

3 files changed

+31
-31
lines changed

README.md

+26-26
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
1-
# fastify-jwt
1+
# @fastify/jwt
22

33
![CI](https://github.com/fastify/fastify-jwt/workflows/CI/badge.svg)
4-
[![NPM version](https://img.shields.io/npm/v/fastify-jwt.svg?style=flat)](https://www.npmjs.com/package/fastify-jwt)
4+
[![NPM version](https://img.shields.io/npm/v/@fastify/jwt.svg?style=flat)](https://www.npmjs.com/package/@fastify/jwt)
55
[![Known Vulnerabilities](https://snyk.io/test/github/fastify/fastify-jwt/badge.svg)](https://snyk.io/test/github/fastify/fastify-jwt)
66
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://standardjs.com/)
77

88
JWT utils for Fastify, internally it uses [fast-jwt](https://github.com/nearform/fast-jwt).
99

1010
**NOTE:** The plugin has been migrated from using `jsonwebtoken` to `fast-jwt`. Even though `fast-jwt` has 1:1 feature implementation with `jsonwebtoken`, some _exotic_ implementations might break. In that case please open an issue with details of your implementation. See [Upgrading notes](UPGRADING.md) for more details about what changes this migration introduced.
1111

12-
`fastify-jwt` supports Fastify@3.
13-
`fastify-jwt` [v1.x](https://github.com/fastify/fastify-jwt/tree/1.x)
12+
`@fastify/jwt` supports Fastify@3.
13+
`@fastify/jwt` [v1.x](https://github.com/fastify/fastify-jwt/tree/1.x)
1414
supports both Fastify@2.
1515

1616
## Install
1717
```
18-
npm i fastify-jwt --save
18+
npm i @fastify/jwt --save
1919
```
2020

2121
## Usage
2222
Register as a plugin. This will decorate your `fastify` instance with the following methods: `decode`, `sign`, and `verify`; refer to their documentation to find how to use the utilities. It will also register `request.jwtVerify` and `reply.jwtSign`. You must pass a `secret` when registering the plugin.
2323

2424
```js
2525
const fastify = require('fastify')()
26-
fastify.register(require('fastify-jwt'), {
26+
fastify.register(require('@fastify/jwt'), {
2727
secret: 'supersecret'
2828
})
2929

@@ -42,7 +42,7 @@ For verifying & accessing the decoded token inside your services, you can use a
4242

4343
```js
4444
const fastify = require('fastify')()
45-
fastify.register(require('fastify-jwt'), {
45+
fastify.register(require('@fastify/jwt'), {
4646
secret: 'supersecret'
4747
})
4848

@@ -71,7 +71,7 @@ However, most of the time we want to protect only some of the routes in our appl
7171
const fp = require("fastify-plugin")
7272

7373
module.exports = fp(async function(fastify, opts) {
74-
fastify.register(require("fastify-jwt"), {
74+
fastify.register(require("@fastify/jwt"), {
7575
secret: "supersecret"
7676
})
7777

@@ -101,7 +101,7 @@ module.exports = async function(fastify, opts) {
101101
}
102102
```
103103

104-
Make sure that you also check [fastify-auth](https://github.com/fastify/fastify-auth) plugin for composing more complex strategies.
104+
Make sure that you also check [@fastify/auth](https://github.com/fastify/fastify-auth) plugin for composing more complex strategies.
105105

106106
### Auth0 tokens verification
107107

@@ -123,7 +123,7 @@ Function based `secret` is supported by the `request.jwtVerify()` and `reply.jwt
123123
const { readFileSync } = require('fs')
124124
const path = require('path')
125125
const fastify = require('fastify')()
126-
const jwt = require('fastify-jwt')
126+
const jwt = require('@fastify/jwt')
127127
// secret as a string
128128
fastify.register(jwt, { secret: 'supersecret' })
129129
// secret as a function with callback
@@ -167,7 +167,7 @@ fastify.register(jwt, {
167167
sign: { algorithm: 'ES256' }
168168
})
169169
```
170-
Optionally you can define global default options that will be used by `fastify-jwt` API if you do not override them.
170+
Optionally you can define global default options that will be used by `@fastify/jwt` API if you do not override them.
171171

172172
Additionally, it is also possible to reject tokens selectively (i.e. blacklisting) by providing the option `trusted` with the following signature: `(request, decodedToken) => boolean|Promise<boolean>|SignPayloadType|Promise<SignPayloadType>` where `request` is a `FastifyRequest` and `decodedToken` is the parsed (and verified) token information. Its result should be `false` or `Promise<false>` if the token should be rejected or, otherwise, be `true` or `Promise<true>` if the token should be accepted and, considering that `request.user` will be used after that, the return should be `decodedToken` itself.
173173

@@ -176,7 +176,7 @@ Additionally, it is also possible to reject tokens selectively (i.e. blacklistin
176176
const { readFileSync } = require('fs')
177177
const path = require('path')
178178
const fastify = require('fastify')()
179-
const jwt = require('fastify-jwt')
179+
const jwt = require('@fastify/jwt')
180180
fastify.register(jwt, {
181181
secret: {
182182
private: readFileSync(`${path.join(__dirname, 'certs')}/private.pem`, 'utf8')
@@ -244,9 +244,9 @@ fastify.listen(3000, err => {
244244

245245
#### Example using cookie
246246

247-
In some situations you may want to store a token in a cookie. This allows you to drastically reduce the attack surface of XSS on your web app with the [`httpOnly`](https://wiki.owasp.org/index.php/HttpOnly) and `secure` flags. Cookies can be susceptible to CSRF. You can mitigate this by either setting the [`sameSite`](https://www.owasp.org/index.php/SameSite) flag to `strict`, or by using a CSRF library such as [`fastify-csrf`](https://www.npmjs.com/package/fastify-csrf).
247+
In some situations you may want to store a token in a cookie. This allows you to drastically reduce the attack surface of XSS on your web app with the [`httpOnly`](https://wiki.owasp.org/index.php/HttpOnly) and `secure` flags. Cookies can be susceptible to CSRF. You can mitigate this by either setting the [`sameSite`](https://www.owasp.org/index.php/SameSite) flag to `strict`, or by using a CSRF library such as [`@fastify/csrf`](https://www.npmjs.com/package/@fastify/csrf).
248248

249-
**Note:** This plugin will look for a decorated request with the `cookies` property. [`fastify-cookie`](https://www.npmjs.com/package/fastify-cookie) supports this feature, and therefore you should use it when using the cookie feature. The plugin will fallback to looking for the token in the authorization header if either of the following happens (even if the cookie option is enabled):
249+
**Note:** This plugin will look for a decorated request with the `cookies` property. [`@fastify/cookie`](https://www.npmjs.com/package/@fastify/cookie) supports this feature, and therefore you should use it when using the cookie feature. The plugin will fallback to looking for the token in the authorization header if either of the following happens (even if the cookie option is enabled):
250250

251251
- The request has both the authorization and cookie header
252252
- Cookie is empty, authorization header is present
@@ -255,7 +255,7 @@ If you are signing your cookie, you can set the `signed` boolean to `true` which
255255

256256
```js
257257
const fastify = require('fastify')()
258-
const jwt = require('fastify-jwt')
258+
const jwt = require('@fastify/jwt')
259259

260260
fastify.register(jwt, {
261261
secret: 'foobar'
@@ -266,7 +266,7 @@ fastify.register(jwt, {
266266
})
267267

268268
fastify
269-
.register(require('fastify-cookie'))
269+
.register(require('@fastify/cookie'))
270270

271271
fastify.get('/cookies', async (request, reply) => {
272272
const token = await reply.jwtSign({
@@ -303,7 +303,7 @@ fastify.listen(3000, err => {
303303
```js
304304
const fastify = require('fastify')()
305305

306-
fastify.register(require('fastify-jwt'), {
306+
fastify.register(require('@fastify/jwt'), {
307307
secret: 'foobar',
308308
trusted: validateToken
309309
})
@@ -335,7 +335,7 @@ You may customize the `request.user` object setting a custom sync function as pa
335335

336336
```js
337337
const fastify = require('fastify')();
338-
fastify.register(require('fastify-jwt'), {
338+
fastify.register(require('@fastify/jwt'), {
339339
formatUser: function (user) {
340340
return {
341341
departmentName: user.department_name,
@@ -405,7 +405,7 @@ const myCustomMessages = {
405405
}
406406
}
407407

408-
fastify.register(require('fastify-jwt'), {
408+
fastify.register(require('@fastify/jwt'), {
409409
secret: 'supersecret',
410410
messages: myCustomMessages
411411
})
@@ -479,7 +479,7 @@ For your convenience, the `decode`, `sign`, `verify` and `messages` options you
479479
const { readFileSync } = require('fs')
480480
const path = require('path')
481481
const fastify = require('fastify')()
482-
const jwt = require('fastify-jwt')
482+
const jwt = require('@fastify/jwt')
483483
fastify.register(jwt, {
484484
secret: {
485485
private: readFileSync(`${path.join(__dirname, 'certs')}/private.key`),
@@ -555,7 +555,7 @@ As of 3.2.0, decorated when `options.jwtDecode` is truthy. Will become non-condi
555555

556556
### Algorithms supported
557557

558-
The following algorithms are currently supported by [fast-jwt](https://github.com/nearform/fast-jwt) that is internally used by `fastify-jwt`.
558+
The following algorithms are currently supported by [fast-jwt](https://github.com/nearform/fast-jwt) that is internally used by `@fastify/jwt`.
559559

560560
**Name** | **Description**
561561
----------------|----------------------------
@@ -585,7 +585,7 @@ You can find the list [here](https://github.com/nearform/fast-jwt#algorithms-sup
585585
#### Signing and verifying (jwtSign, jwtVerify)
586586
```js
587587
const fastify = require('fastify')()
588-
const jwt = require('fastify-jwt')
588+
const jwt = require('@fastify/jwt')
589589
const request = require('request')
590590

591591
fastify.register(jwt, {
@@ -652,7 +652,7 @@ The following example integrates the [get-jwks](https://github.com/nearform/get-
652652
##### Example
653653
```js
654654
const Fastify = require('fastify')
655-
const fjwt = require('fastify-jwt')
655+
const fjwt = require('@fastify/jwt')
656656
const buildGetJwks = require('get-jwks')
657657

658658
const fastify = Fastify()
@@ -684,7 +684,7 @@ This plugin has two available exports, the default plugin function `fastifyJwt`
684684
Import them like so:
685685

686686
```ts
687-
import fastifyJwt, { FastifyJWTOptions } from 'fastify-jwt'
687+
import fastifyJwt, { FastifyJWTOptions } from '@fastify/jwt'
688688
```
689689

690690

@@ -693,9 +693,9 @@ Define custom Payload Type and Attached User Type to request object
693693
694694
```ts
695695
// fastify-jwt.d.ts
696-
import "fastify-jwt"
696+
import "@fastify/jwt"
697697

698-
declare module "fastify-jwt" {
698+
declare module "@fastify/jwt" {
699699
interface FastifyJWT {
700700
payload: { id: number } // payload type is used for signing and verifying
701701
user: {

UPGRADING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
## Upgrading Notes
2-
This document captures breaking changes between versions of `fastify-jwt`.
2+
This document captures breaking changes between versions of `@fastify/jwt`.
33

44
### Upgrading from 3.x to 4.0
55

example/UsingCertificates.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Code example
1414
```js
1515
const { readFileSync } = require('fs')
1616
const fastify = require('fastify')()
17-
const jwt = require('fastify-jwt')
17+
const jwt = require('@fastify/jwt')
1818

1919
fastify.register(jwt, {
2020
secret: {
@@ -43,7 +43,7 @@ Code example
4343
```js
4444
const { readFileSync } = require('fs')
4545
const fastify = require('fastify')()
46-
const jwt = require('fastify-jwt')
46+
const jwt = require('@fastify/jwt')
4747

4848
fastify.register(jwt, {
4949
secret: {
@@ -74,7 +74,7 @@ Code example
7474
```js
7575
const { readFileSync } = require('fs')
7676
const fastify = require('fastify')()
77-
const jwt = require('fastify-jwt')
77+
const jwt = require('@fastify/jwt')
7878

7979
fastify.register(jwt, {
8080
secret: {
@@ -103,7 +103,7 @@ Code example
103103
```js
104104
const { readFileSync } = require('fs')
105105
const fastify = require('fastify')()
106-
const jwt = require('fastify-jwt')
106+
const jwt = require('@fastify/jwt')
107107

108108
fastify.register(jwt, {
109109
secret: {

0 commit comments

Comments
 (0)