Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
ea136cf1a5
|
|||
|
457a989fe3
|
|||
|
9f74c8b56c
|
|||
|
c7ce8686d3
|
@@ -100,7 +100,7 @@ Argument | Type | Status | Defa
|
|||||||
`secret` | `string`, `JsonWebKey`, `CryptoKey` | required | - | A string which is used to sign the payload.
|
`secret` | `string`, `JsonWebKey`, `CryptoKey` | required | - | A string which is used to sign the payload.
|
||||||
`options` | `string`, `object` | optional | `HS256` | Either the `algorithm` string or an object.
|
`options` | `string`, `object` | optional | `HS256` | Either the `algorithm` string or an object.
|
||||||
`options.algorithm` | `string` | optional | `HS256` | See [Available Algorithms](#available-algorithms)
|
`options.algorithm` | `string` | optional | `HS256` | See [Available Algorithms](#available-algorithms)
|
||||||
`options.keyid` | `string` | optional | `undefined` | The `keyid` or `kid` to be set in the header of the resulting JWT.
|
`options.header` | `object` | optional | `undefined` | Extend the header of the resulting JWT.
|
||||||
|
|
||||||
|
|
||||||
#### `return`
|
#### `return`
|
||||||
@@ -142,6 +142,7 @@ Returns the decoded token or `undefined`.
|
|||||||
typ: "JWT"
|
typ: "JWT"
|
||||||
},
|
},
|
||||||
payload: {
|
payload: {
|
||||||
|
sub: "1234",
|
||||||
name: "John Doe",
|
name: "John Doe",
|
||||||
email: "john.doe@gmail.com"
|
email: "john.doe@gmail.com"
|
||||||
}
|
}
|
||||||
@@ -173,6 +174,7 @@ Returns an `object` containing `header` and `payload`:
|
|||||||
typ: "JWT"
|
typ: "JWT"
|
||||||
},
|
},
|
||||||
payload: {
|
payload: {
|
||||||
|
sub: "1234",
|
||||||
name: "John Doe",
|
name: "John Doe",
|
||||||
email: "john.doe@gmail.com"
|
email: "john.doe@gmail.com"
|
||||||
}
|
}
|
||||||
|
|||||||
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": "3.0.0",
|
"version": "3.1.1",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@tsndr/cloudflare-worker-jwt",
|
"name": "@tsndr/cloudflare-worker-jwt",
|
||||||
"version": "3.0.0",
|
"version": "3.1.1",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@cloudflare/workers-types": "^4.20240925.0",
|
"@cloudflare/workers-types": "^4.20240925.0",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@tsndr/cloudflare-worker-jwt",
|
"name": "@tsndr/cloudflare-worker-jwt",
|
||||||
"version": "3.0.0",
|
"version": "3.1.1",
|
||||||
"description": "A lightweight JWT implementation with ZERO dependencies for Cloudflare Worker",
|
"description": "A lightweight JWT implementation with ZERO dependencies for Cloudflare Worker",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"exports": "./index.js",
|
"exports": "./index.js",
|
||||||
|
|||||||
@@ -147,7 +147,7 @@ export async function sign<Payload = {}, Header = {}>(payload: JwtPayload<Payloa
|
|||||||
if (typeof options === "string")
|
if (typeof options === "string")
|
||||||
options = { algorithm: options }
|
options = { algorithm: options }
|
||||||
|
|
||||||
options = { algorithm: "HS256", header: { typ: "JWT" } as JwtHeader<Header>, ...options }
|
options = { algorithm: "HS256", header: { typ: "JWT", ...(options.header ?? {}) } as JwtHeader<Header>, ...options }
|
||||||
|
|
||||||
if (!payload || typeof payload !== "object")
|
if (!payload || typeof payload !== "object")
|
||||||
throw new Error("payload must be an object")
|
throw new Error("payload must be an object")
|
||||||
|
|||||||
Reference in New Issue
Block a user