@elysiajs/jwt 1.4.1 → 1.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -106
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,120 +1,46 @@
|
|
|
1
|
-
# @
|
|
1
|
+
# @elysia/jwt
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[Elysia](https://github.com/elysiajs/elysia) plugin to integrate JSON Web Tokens (JWT).
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
bun add @
|
|
8
|
+
bun add @elysia/jwt
|
|
9
9
|
```
|
|
10
10
|
|
|
11
11
|
## Example
|
|
12
12
|
|
|
13
13
|
```typescript
|
|
14
|
-
import { Elysia, t } from 'elysia'
|
|
15
|
-
import { jwt } from '@
|
|
14
|
+
import { Elysia, t } from 'elysia'
|
|
15
|
+
import { jwt } from '@elysia/jwt'
|
|
16
16
|
|
|
17
17
|
const app = new Elysia()
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
18
|
+
.use(
|
|
19
|
+
jwt({
|
|
20
|
+
name: 'jwt',
|
|
21
|
+
// This should be Environment Variable
|
|
22
|
+
secret: 'MY_SECRETS'
|
|
23
|
+
})
|
|
24
|
+
)
|
|
25
|
+
.get('/sign/:name', async ({ jwt, cookie: { auth }, params }) => {
|
|
26
|
+
auth.set({
|
|
27
|
+
value: await jwt.sign(params),
|
|
28
|
+
httpOnly: true
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
return `Sign in as ${params.name}`
|
|
32
|
+
})
|
|
33
|
+
.get('/profile', async ({ jwt, set, cookie: { auth } }) => {
|
|
34
|
+
const profile = await jwt.verify(auth)
|
|
35
|
+
|
|
36
|
+
if (!profile) {
|
|
37
|
+
set.status = 401
|
|
38
|
+
return 'Unauthorized'
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return `Hello ${profile.name}`
|
|
42
|
+
})
|
|
43
|
+
.listen(3000)
|
|
44
44
|
```
|
|
45
45
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
This package extends [jose](https://github.com/panva/jose), most config is inherited from Jose.
|
|
49
|
-
|
|
50
|
-
Below are configurable properties for using JWT plugin
|
|
51
|
-
|
|
52
|
-
### name
|
|
53
|
-
|
|
54
|
-
Name to decorate method as:
|
|
55
|
-
|
|
56
|
-
For example, `jwt` will decorate Context with `Context.jwt`
|
|
57
|
-
|
|
58
|
-
### secret
|
|
59
|
-
|
|
60
|
-
JWT secret key
|
|
61
|
-
|
|
62
|
-
### schema
|
|
63
|
-
|
|
64
|
-
Type strict validation for JWT payload
|
|
65
|
-
|
|
66
|
-
## Jose's config
|
|
67
|
-
|
|
68
|
-
Below is the config inherits from [jose](https://github.com/panva/jose)
|
|
69
|
-
|
|
70
|
-
### alg
|
|
71
|
-
|
|
72
|
-
@default 'HS256'
|
|
73
|
-
|
|
74
|
-
Algorithm to sign JWT with
|
|
75
|
-
|
|
76
|
-
### crit
|
|
77
|
-
|
|
78
|
-
Critical Header Parameter.
|
|
79
|
-
|
|
80
|
-
### iss
|
|
81
|
-
|
|
82
|
-
JWT Issuer
|
|
83
|
-
|
|
84
|
-
@see [RFC7519#section-4.1.1](https://www.rfc-editor.org/rfc/rfc7519#section-4.1.1)
|
|
85
|
-
|
|
86
|
-
### sub
|
|
87
|
-
|
|
88
|
-
JWT Subject
|
|
89
|
-
|
|
90
|
-
@see [RFC7519#section-4.1.2](https://www.rfc-editor.org/rfc/rfc7519#section-4.1.2)
|
|
91
|
-
|
|
92
|
-
### aud
|
|
93
|
-
|
|
94
|
-
JWT Audience
|
|
95
|
-
|
|
96
|
-
@see [RFC7519#section-4.1.3](https://www.rfc-editor.org/rfc/rfc7519#section-4.1.3)
|
|
97
|
-
|
|
98
|
-
### jti
|
|
99
|
-
|
|
100
|
-
JWT ID
|
|
101
|
-
|
|
102
|
-
@see [RFC7519#section-4.1.7](https://www.rfc-editor.org/rfc/rfc7519#section-4.1.7)
|
|
103
|
-
|
|
104
|
-
### nbf
|
|
105
|
-
|
|
106
|
-
JWT Not Before
|
|
107
|
-
|
|
108
|
-
@see [RFC7519#section-4.1.5](https://www.rfc-editor.org/rfc/rfc7519#section-4.1.5)
|
|
109
|
-
|
|
110
|
-
### exp
|
|
111
|
-
|
|
112
|
-
JWT Expiration Time
|
|
113
|
-
|
|
114
|
-
@see [RFC7519#section-4.1.4](https://www.rfc-editor.org/rfc/rfc7519#section-4.1.4)
|
|
115
|
-
|
|
116
|
-
### iat
|
|
117
|
-
|
|
118
|
-
JWT Issued At
|
|
119
|
-
|
|
120
|
-
@see [RFC7519#section-4.1.6](https://www.rfc-editor.org/rfc/rfc7519#section-4.1.6)
|
|
46
|
+
See [documentation](https://elysiajs.com/plugins/jwt.html) for more details.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elysiajs/jwt",
|
|
3
|
-
"description": "
|
|
4
|
-
"version": "1.4.
|
|
3
|
+
"description": "Elysia plugin to integrate JSON Web Tokens (JWT)",
|
|
4
|
+
"version": "1.4.2",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "saltyAom",
|
|
7
7
|
"url": "https://github.com/SaltyAom",
|