README
Table of contents
About
jwt-promisify is a promisified version of jsonwebtoken with TypeScript support.
- Easy-to-use promises
- TypeScript support
Installation
Install it using npm:
npm install jwt-promisify --save
Usage
var jwt = require("jwt-promisify");
jwt.sign(payload, secretOrPrivateKey, [options])
Signs the payload and returns a token.
| Parameter | Type | Optional | Default | Description |
|---|---|---|---|---|
| payload | String, Buffer, Object | ❌ | None | Token payload. |
| secretOrPublicKey | String, Buffer, { key, passphrase } |
❌ | None | Key or certificate to sing token. |
| options | SignOptions | ✔ | None | Options for signing. |
jwt.validate(token, secretOrPublicKey, [options])
Verifies a token with a secret or public key and returns the payload.
| Parameter | Type | Optional | Default | Description |
|---|---|---|---|---|
| token | String | ❌ | None | Token to be verified. |
| secretOrPublicKey | String, Buffer | ❌ | None | Key or certificate to verify token against. |
| options | VerifyOptions | ✔ | None | Options for the verification. |
jwt.decode(token, [options])
Returns the payload without verifying if the signature is valid.
| Parameter | Type | Optional | Default | Description |
|---|---|---|---|---|
| token | String | ❌ | None | Token to be decoded. |
| options | DecodeOptions | ✔ | None | Options for decoding. |
SignOptions
Options for signing the token.
| Parameter | Type | Optional | Default | Description |
|---|---|---|---|---|
| algorithm | Algorithm | ✔ | HS256 | Signing algorithm. |
| audience | String, Array<String> | ✔ | None | The token's audience. |
| encoding | String | ✔ | None | The token's encoding. |
| expiresIn | String, Number | ✔ | None | Expressed in seconds or a string describing a time span vercel/ms. |
| header | Object | ✔ | None | The token's header. |
| Issuer | String | ✔ | None | The token's issuer. |
| jwtid | String | ✔ | None | JWTID. |
| keyid | String | ✔ | None | KeyID. |
| noTimestamp | Boolean | ✔ | None | Whether the token has a timestamp or not. |
| notBefore | String, Number | ✔ | None | Expressed in seconds or a string describing a time span vercel/ms. |
| mutatePayload | Boolean | ✔ | false | Whether the payload will be modified by signing or not. |
| subject | String | ✔ | None | The token's subject. |
VerifyOptions
Options for the validation.
| Parameter | Type | Optional | Default | Description |
|---|---|---|---|---|
| algorithms | Array<Algorithm> | ✔ | None | List of the names of allowed algorithms. |
| audience | String, RegExp, Array<String | RegExp> | ✔ | None | The token's expected audience. |
| clockTolerance | Number | ✔ | 0 | Number of seconds to tolerate when checking nbf and exp claims. |
| complete | Boolean | ✔ | false | Return an object { header, payload, signature } instead of only the content of the payload. |
| issuer | String | ✔ | None | The token's expected issuer. |
| ignoreExpiration | Boolean | ✔ | false | Whether to ignore the expiration or not. |
| ignoreNotBefore | Boolean | ✔ | false | Whether to ignore the activation timestamp or not. |
| jwtid | String | ✔ | None | If you want to check the JWTID, provide a value here. |
| maxAge | String, Number | ✔ | None | Expressed in seconds or a string describing a time span vercel/ms. |
| nonce | String | ✔ | None | If you want to check the nonce claim, provide a value here. |
DecodeOptions
Options for decoding.
| Parameter | Type | Optional | Default | Description |
|---|---|---|---|---|
| complete | Boolean | ✔ | false | Return an object { header, payload, signature } instead of only the content of the payload. |
| json | Boolean | ✔ | false | Whether to force JSON.parse() on payload or not. |
Algorithm
List of supported algorithms:
| Algorithm | Digital signature or MAC algorithm |
|---|---|
| HS256 | HMAC using SHA-256 hash algorithm. |
| HS384 | HMAC using SHA-384 hash algorithm. |
| HS512 | HMAC using SHA-512 hash algorithm. |
| RS256 | RSASSA-PKCS1-v1_5 using SHA-256 hash algorithm. |
| RS384 | RSASSA-PKCS1-v1_5 using SHA-384 hash algorithm. |
| RS512 | RSASSA-PKCS1-v1_5 using SHA-512 hash algorithm. |
| PS256 | RSASSA-PSS using SHA-256 hash algorithm (only node ^6.12.0 OR >=8.0.0). |
| PS384 | RSASSA-PSS using SHA-384 hash algorithm (only node ^6.12.0 OR >=8.0.0). |
| PS512 | RSASSA-PSS using SHA-512 hash algorithm (only node ^6.12.0 OR >=8.0.0). |
| ES256 | ECDSA using P-256 curve and SHA-256 hash algorithm. |
| ES384 | ECDSA using P-384 curve and SHA-384 hash algorithm. |
| ES512 | ECDSA using P-521 curve and SHA-512 hash algorithm. |
| none | No digital signature or MAC value included. |
Links
License
This project is licensed under MIT.
© 2020 Wlad Gumenyuk