Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| af3ea4cf8d | |||
| d99e361d65 | |||
| 79f030a35a | |||
| 5fd472c33d | |||
| 54ad90f6fd |
@@ -1,4 +1,4 @@
|
||||
name: Publish NPM Package
|
||||
name: Publish
|
||||
|
||||
on:
|
||||
release:
|
||||
97
README.md
97
README.md
@@ -2,11 +2,13 @@
|
||||
|
||||
A lightweight JWT implementation with ZERO dependencies for Cloudflare Workers.
|
||||
|
||||
|
||||
## Contents
|
||||
|
||||
- [Install](#install)
|
||||
- [Usage](#usage)
|
||||
- [Examples](#examples)
|
||||
- [Usage](#usage)
|
||||
|
||||
|
||||
## Install
|
||||
|
||||
@@ -14,52 +16,6 @@ A lightweight JWT implementation with ZERO dependencies for Cloudflare Workers.
|
||||
npm i @tsndr/cloudflare-worker-jwt
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
<hr>
|
||||
|
||||
### `jwt.sign(payload, secret, [algorithm])`
|
||||
|
||||
Signs a payload and returns the token.
|
||||
|
||||
#### Arguments
|
||||
|
||||
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`
|
||||
|
||||
#### `return`
|
||||
returns token as a `string`
|
||||
|
||||
<hr>
|
||||
|
||||
### `jwt.verify(token, secret, [algorithm])`
|
||||
|
||||
Verifies the integrity of the token and returns a boolean value.
|
||||
|
||||
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`
|
||||
|
||||
#### `return`
|
||||
Returns `true` if signature, `nbf` (if set) and `exp` (if set) are valid, otherwise returns `false`.
|
||||
|
||||
<hr>
|
||||
|
||||
### `jwt.decode(token)`
|
||||
|
||||
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
|
||||
----------- | -------- | -------- | ------- | -----------
|
||||
`token` | `string` | required | - | The token string generated by `jwt.sign()`.
|
||||
|
||||
#### `return`
|
||||
Returns payload `object`.
|
||||
|
||||
## Examples
|
||||
|
||||
@@ -101,3 +57,50 @@ async () => {
|
||||
const payload = jwt.decode(token) // { name: 'John Doe', email: 'john.doe@gmail.com', ... }
|
||||
}
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
<hr>
|
||||
|
||||
### `jwt.sign(payload, secret, [algorithm])`
|
||||
|
||||
Signs a payload and returns the token.
|
||||
|
||||
#### Arguments
|
||||
|
||||
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`
|
||||
|
||||
#### `return`
|
||||
Returns token as a `string`.
|
||||
|
||||
<hr>
|
||||
|
||||
### `jwt.verify(token, secret, [algorithm])`
|
||||
|
||||
Verifies the integrity of the token and returns a boolean value.
|
||||
|
||||
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`
|
||||
|
||||
#### `return`
|
||||
Returns `true` if signature, `nbf` (if set) and `exp` (if set) are valid, otherwise returns `false`.
|
||||
|
||||
<hr>
|
||||
|
||||
### `jwt.decode(token)`
|
||||
|
||||
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
|
||||
----------- | -------- | -------- | ------- | -----------
|
||||
`token` | `string` | required | - | The token string generated by `jwt.sign()`.
|
||||
|
||||
#### `return`
|
||||
Returns payload `object`.
|
||||
32
index.d.ts
vendored
32
index.d.ts
vendored
@@ -1,6 +1,38 @@
|
||||
/**
|
||||
* JWT
|
||||
*
|
||||
* @class
|
||||
* @constructor
|
||||
* @public
|
||||
*/
|
||||
declare class JWT {
|
||||
|
||||
/**
|
||||
* Signs a payload and returns the token
|
||||
*
|
||||
* @param {object} payload The payload object. To use `nbf` (Not Before) and/or `exp` (Expiration Time) add `nbf` and/or `exp` to the payload.
|
||||
* @param {string} secret A string which is used to sign the payload.
|
||||
* @param {'HS256' | 'HS512'} [algorithm=HS256] The algorithm used to sign the payload, possible values: `HS256` or `HS512`
|
||||
* @returns {Promise<string>} Returns token as a `string`.
|
||||
*/
|
||||
sign(payload: object, secret: string, algorithm?: "HS256" | "HS512"): Promise<string>
|
||||
|
||||
/**
|
||||
* Verifies the integrity of the token and returns a boolean value.
|
||||
*
|
||||
* @param {string} token The token string generated by `jwt.sign()`.
|
||||
* @param {string} secret The string which was used to sign the payload.
|
||||
* @param {'HS256' | 'HS512'} [algorithm=HS256] The algorithm used to sign the payload, possible values: `HS256` or `HS512`
|
||||
* @returns {Promise<boolean>} Returns `true` if signature, `nbf` (if set) and `exp` (if set) are valid, otherwise returns `false`.
|
||||
*/
|
||||
verify(token: string, secret: string, algorithm?: "HS256" | "HS512"): Promise<boolean>
|
||||
|
||||
/**
|
||||
* Returns the payload **without** verifying the integrity of the token. Please use `jwt.verify()` first to keep your application secure!
|
||||
*
|
||||
* @param {string} token The token string generated by `jwt.sign()`.
|
||||
* @returns {object | null} Returns payload `object`.
|
||||
*/
|
||||
decode(token: string): object | null
|
||||
}
|
||||
declare const _exports: JWT
|
||||
|
||||
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "@tsndr/cloudflare-worker-jwt",
|
||||
"version": "1.0.7",
|
||||
"version": "1.1.2",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@tsndr/cloudflare-worker-jwt",
|
||||
"version": "1.0.7",
|
||||
"version": "1.1.2",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"tslint": "^6.1.3"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@tsndr/cloudflare-worker-jwt",
|
||||
"version": "1.1.0",
|
||||
"version": "1.1.2",
|
||||
"description": "A lightweight JWT implementation with ZERO dependencies for Cloudflare Worker",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
"no-string-throw": true,
|
||||
"no-tautology-expression": true,
|
||||
"no-this-assignment": [true, {"allowed-names": ["^self$"], "allow-destructuring": true}],
|
||||
"no-trailing-whitespace": true,
|
||||
"no-trailing-whitespace": [true, "ignore-comments", "ignore-jsdoc"],
|
||||
"no-unnecessary-callback-wrapper": true,
|
||||
"no-unnecessary-initializer": true,
|
||||
"no-unsafe-finally": true,
|
||||
|
||||
Reference in New Issue
Block a user