Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
1de6acbfff
|
|||
|
b002db4547
|
|||
|
1bdbd0a5c5
|
|||
|
883ec55b73
|
|||
|
|
c515fb76e6 | ||
|
ec41207832
|
|||
|
e64e89f325
|
@@ -16,7 +16,7 @@ A lightweight JWT implementation with ZERO dependencies for Cloudflare Workers.
|
|||||||
## Install
|
## Install
|
||||||
|
|
||||||
```
|
```
|
||||||
npm i -D @tsndr/cloudflare-worker-jwt
|
npm i @tsndr/cloudflare-worker-jwt
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
@@ -84,7 +84,7 @@ Signs a payload and returns the token.
|
|||||||
|
|
||||||
#### Arguments
|
#### Arguments
|
||||||
|
|
||||||
Argument | Type | Satus | Default | Description
|
Argument | Type | Status | Default | Description
|
||||||
----------- | -------- | -------- | ------- | -----------
|
----------- | -------- | -------- | ------- | -----------
|
||||||
`payload` | `object` | required | - | The payload object. To use `nbf` (Not Before) and/or `exp` (Expiration Time) add `nbf` and/or `exp` to the payload.
|
`payload` | `object` | required | - | The payload object. To use `nbf` (Not Before) and/or `exp` (Expiration Time) add `nbf` and/or `exp` to the payload.
|
||||||
`secret` | `string` | required | - | A string which is used to sign the payload.
|
`secret` | `string` | required | - | A string which is used to sign the payload.
|
||||||
@@ -100,7 +100,7 @@ Returns token as a `string`.
|
|||||||
|
|
||||||
Verifies the integrity of the token and returns a boolean value.
|
Verifies the integrity of the token and returns a boolean value.
|
||||||
|
|
||||||
Argument | Type | Satus | Default | Description
|
Argument | Type | Status | Default | Description
|
||||||
----------- | -------- | -------- | ------- | -----------
|
----------- | -------- | -------- | ------- | -----------
|
||||||
`token` | `string` | required | - | The token string generated by `jwt.sign()`.
|
`token` | `string` | required | - | The token string generated by `jwt.sign()`.
|
||||||
`secret` | `string` | required | - | The string which was used to sign the payload.
|
`secret` | `string` | required | - | The string which was used to sign the payload.
|
||||||
@@ -119,7 +119,7 @@ Returns `true` if signature, `nbf` (if set) and `exp` (if set) are valid, otherw
|
|||||||
|
|
||||||
Returns the payload **without** verifying the integrity of the token. Please use `jwt.verify()` first to keep your application secure!
|
Returns the payload **without** verifying the integrity of the token. Please use `jwt.verify()` first to keep your application secure!
|
||||||
|
|
||||||
Argument | Type | Satus | Default | Description
|
Argument | Type | Status | Default | Description
|
||||||
----------- | -------- | -------- | ------- | -----------
|
----------- | -------- | -------- | ------- | -----------
|
||||||
`token` | `string` | required | - | The token string generated by `jwt.sign()`.
|
`token` | `string` | required | - | The token string generated by `jwt.sign()`.
|
||||||
|
|
||||||
|
|||||||
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "@tsndr/cloudflare-worker-jwt",
|
"name": "@tsndr/cloudflare-worker-jwt",
|
||||||
"version": "2.1.1",
|
"version": "2.1.4",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@tsndr/cloudflare-worker-jwt",
|
"name": "@tsndr/cloudflare-worker-jwt",
|
||||||
"version": "2.1.1",
|
"version": "2.1.4",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@cloudflare/workers-types": "^3.13.0",
|
"@cloudflare/workers-types": "^3.13.0",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@tsndr/cloudflare-worker-jwt",
|
"name": "@tsndr/cloudflare-worker-jwt",
|
||||||
"version": "2.1.1",
|
"version": "2.1.4",
|
||||||
"description": "A lightweight JWT implementation with ZERO dependencies for Cloudflare Worker",
|
"description": "A lightweight JWT implementation with ZERO dependencies for Cloudflare Worker",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"types": "index.d.ts",
|
"types": "index.d.ts",
|
||||||
|
|||||||
@@ -196,6 +196,7 @@ export async function sign(payload: JwtPayload, secret: string, options: JwtSign
|
|||||||
if (!algorithm)
|
if (!algorithm)
|
||||||
throw new Error('algorithm not found')
|
throw new Error('algorithm not found')
|
||||||
|
|
||||||
|
if (!payload.iat)
|
||||||
payload.iat = Math.floor(Date.now() / 1000)
|
payload.iat = Math.floor(Date.now() / 1000)
|
||||||
|
|
||||||
const payloadAsJSON = JSON.stringify(payload)
|
const payloadAsJSON = JSON.stringify(payload)
|
||||||
|
|||||||
Reference in New Issue
Block a user