1
0

Added more algorithms, keyid and did some cleanup

This commit is contained in:
2021-10-27 01:22:01 +02:00
parent 472946f995
commit 9ab38705b6
5 changed files with 79 additions and 476 deletions

View File

@@ -13,7 +13,7 @@ A lightweight JWT implementation with ZERO dependencies for Cloudflare Workers.
## Install
```
npm i @tsndr/cloudflare-worker-jwt
npm i -D @tsndr/cloudflare-worker-jwt
```
@@ -70,7 +70,7 @@ async () => {
<hr>
### `jwt.sign(payload, secret, [algorithm])`
### `jwt.sign(payload, secret, [options])`
Signs a payload and returns the token.
@@ -80,14 +80,14 @@ Argument | Type | Satus | 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.
`secret` | `string` | required | - | A string which is used to sign the payload.
`algorithm` | `string` | optional | `HS256` | The algorithm used to sign the payload, possible values: `HS256` or `HS512`
`options` | `object`, `string` | optional | `{ algorithm: 'HS256' }` | The options object supporting `algorithm` and `keyid` or just the algorithm string. (See [Available Algorithms](#available-algorithms))
#### `return`
Returns token as a `string`.
<hr>
### `jwt.verify(token, secret, [algorithm])`
### `jwt.verify(token, secret, [options])`
Verifies the integrity of the token and returns a boolean value.
@@ -95,7 +95,7 @@ Argument | Type | Satus | Default | Description
----------- | -------- | -------- | ------- | -----------
`token` | `string` | required | - | The token string generated by `jwt.sign()`.
`secret` | `string` | required | - | The string which was used to sign the payload.
`algorithm` | `string` | optional | `HS256` | The algorithm used to sign the payload, possible values: `HS256` or `HS512`
`algorithm` | `object`, `string` | optional | `{ algorithm: 'HS256' }` | The options object supporting `algorithm` or just the algorithm string. (See [Available Algorithms](#available-algorithms))
#### `return`
Returns `true` if signature, `nbf` (if set) and `exp` (if set) are valid, otherwise returns `false`.
@@ -112,3 +112,11 @@ Argument | Type | Satus | Default | Description
#### `return`
Returns payload `object`.
### Available Algorithms
- ES256
- ES384
- ES512
- HS256
- HS384
- HS512