![Introducing Enhanced Alert Actions and Triage Functionality](https://cdn.sanity.io/images/cgdhsj6q/production/fe71306d515f85de6139b46745ea7180362324f0-2530x946.png?w=800&fit=max&auto=format)
Product
Introducing Enhanced Alert Actions and Triage Functionality
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
@tsndr/cloudflare-worker-jwt
Advanced tools
Readme
A lightweight JWT implementation with ZERO dependencies for Cloudflare Workers.
npm i @tsndr/cloudflare-worker-jwt
async () => {
import jwt from '@tsndr/cloudflare-worker-jwt'
// Creating a token
const token = await jwt.sign({ name: 'John Doe', email: 'john.doe@gmail.com' }, 'secret')
// Verifing token
const isValid = await jwt.verify(token, 'secret')
// Check for validity
if (!isValid)
return
// Decoding token
const { payload } = jwt.decode(token)
}
async () => {
import jwt from '@tsndr/cloudflare-worker-jwt'
// Creating a token
const token = await jwt.sign({
name: 'John Doe',
email: 'john.doe@gmail.com',
nbf: Math.floor(Date.now() / 1000) + (60 * 60), // Not before: Now + 1h
exp: Math.floor(Date.now() / 1000) + (2 * (60 * 60)) // Expires: Now + 2h
}, 'secret')
// Verifing token
const isValid = await jwt.verify(token, 'secret') // false
// Check for validity
if (!isValid)
return
// Decoding token
const { payload } = jwt.decode(token) // { name: 'John Doe', email: 'john.doe@gmail.com', ... }
}
jwt.sign(payload, secret, [options])
Signs a payload and returns the token.
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. |
secret | string | required | - | A string which is used to sign the payload. |
options | string , object | optional | HS256 | Either the algorithm string or an object. |
options.algorithm | string | optional | HS256 | See Available Algorithms |
options.keyid | string | optional | undefined | The keyid or kid to be set in the header of the resulting JWT. |
return
Returns token as a string
.
jwt.verify(token, secret, [options])
Verifies the integrity of the token and returns a boolean value.
Argument | Type | Status | Default | Description |
---|---|---|---|---|
token | string | required | - | The token string generated by jwt.sign() . |
secret | string | required | - | The string which was used to sign the payload. |
options | string , object | optional | HS256 | Either the algorithm string or an object. |
options.algorithm | string | optional | HS256 | See Available Algorithms |
options.clockTolerance | number | optional | 0 | Clock tolerance in seconds, to help with slighly out of sync systems. |
options.throwError | boolean | optional | false | By default this we will only throw implementation errors, only set this to true if you want verification errors to be thrown as well. |
throws
If options.throwError
is true
and the token is invalid, an error will be thrown.
return
Returns true
if signature, nbf
(if set) and exp
(if set) are valid, otherwise returns false
.
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 | Status | Default | Description |
---|---|---|---|---|
token | string | required | - | The token string generated by jwt.sign() . |
return
Returns an object
containing header
and payload
:
{
header: {
alg: 'HS256',
typ: 'JWT'
},
payload: {
name: 'John Doe',
email: 'john.doe@gmail.com'
}
}
FAQs
A lightweight JWT implementation with ZERO dependencies for Cloudflare Worker
The npm package @tsndr/cloudflare-worker-jwt receives a total of 11,775 weekly downloads. As such, @tsndr/cloudflare-worker-jwt popularity was classified as popular.
We found that @tsndr/cloudflare-worker-jwt demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
Security News
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
Security News
OpenSSF is warning open source maintainers to stay vigilant against reputation farming on GitHub, where users artificially inflate their status by manipulating interactions on closed issues and PRs.