@alanszp/jwt 9.1.0 → 10.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/jwt.js +5 -6
- package/dist/jwt.js.map +1 -1
- package/dist/types.d.ts +3 -3
- package/package.json +3 -3
- package/src/jwt.ts +3 -4
- package/src/types.ts +4 -4
package/dist/jwt.js
CHANGED
|
@@ -11,8 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.jwtUserHasRoles = exports.verifyJWT = exports.createTokenPayload = exports.generateJWT = exports.withDefaultVerifyOptions = exports.withDefaultSignOptions = exports.publicKeyFromPem = exports.privateKeyFromPem = exports.JWT_ALGORITHM = void 0;
|
|
13
13
|
const crypto_1 = require("crypto");
|
|
14
|
-
const
|
|
15
|
-
const verify_1 = require("jose/jwt/verify");
|
|
14
|
+
const jose_1 = require("jose");
|
|
16
15
|
exports.JWT_ALGORITHM = "RS512";
|
|
17
16
|
function privateKeyFromPem(key) {
|
|
18
17
|
return (0, crypto_1.createPrivateKey)({
|
|
@@ -40,7 +39,7 @@ function generateJWT(privateKey, user, options) {
|
|
|
40
39
|
return __awaiter(this, void 0, void 0, function* () {
|
|
41
40
|
const key = typeof privateKey === "string" ? privateKeyFromPem(privateKey) : privateKey;
|
|
42
41
|
const opts = withDefaultSignOptions(options);
|
|
43
|
-
return new
|
|
42
|
+
return new jose_1.SignJWT(createTokenPayload(user))
|
|
44
43
|
.setProtectedHeader({ alg: exports.JWT_ALGORITHM })
|
|
45
44
|
.setIssuedAt()
|
|
46
45
|
.setIssuer(opts.issuer)
|
|
@@ -57,7 +56,7 @@ function createTokenPayload(user) {
|
|
|
57
56
|
org: user.organizationReference,
|
|
58
57
|
rls: user.roles,
|
|
59
58
|
prms: user.permissions,
|
|
60
|
-
|
|
59
|
+
seg: user.segmentReference,
|
|
61
60
|
};
|
|
62
61
|
}
|
|
63
62
|
exports.createTokenPayload = createTokenPayload;
|
|
@@ -65,7 +64,7 @@ function verifyJWT(publicKey, token, options) {
|
|
|
65
64
|
return __awaiter(this, void 0, void 0, function* () {
|
|
66
65
|
const key = typeof publicKey === "string" ? publicKeyFromPem(publicKey) : publicKey;
|
|
67
66
|
const opts = withDefaultVerifyOptions(options);
|
|
68
|
-
const verify = yield (0,
|
|
67
|
+
const verify = yield (0, jose_1.jwtVerify)(token, key, {
|
|
69
68
|
issuer: opts.issuer,
|
|
70
69
|
algorithms: [exports.JWT_ALGORITHM],
|
|
71
70
|
audience: opts.audience,
|
|
@@ -77,7 +76,7 @@ function verifyJWT(publicKey, token, options) {
|
|
|
77
76
|
organizationReference: payload.org,
|
|
78
77
|
roles: payload.rls,
|
|
79
78
|
permissions: payload.prms,
|
|
80
|
-
|
|
79
|
+
segmentReference: payload.seg || null,
|
|
81
80
|
};
|
|
82
81
|
});
|
|
83
82
|
}
|
package/dist/jwt.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jwt.js","sourceRoot":"","sources":["../src/jwt.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mCAAsE;AACtE
|
|
1
|
+
{"version":3,"file":"jwt.js","sourceRoot":"","sources":["../src/jwt.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mCAAsE;AACtE,+BAA0C;AAG7B,QAAA,aAAa,GAAG,OAAO,CAAC;AAErC,SAAgB,iBAAiB,CAAC,GAAW;IAC3C,OAAO,IAAA,yBAAgB,EAAC;QACtB,GAAG;QACH,MAAM,EAAE,KAAK;KACd,CAAC,CAAC;AACL,CAAC;AALD,8CAKC;AAED,SAAgB,gBAAgB,CAAC,GAAW;IAC1C,OAAO,IAAA,wBAAe,EAAC;QACrB,GAAG;QACH,MAAM,EAAE,KAAK;KACd,CAAC,CAAC;AACL,CAAC;AALD,4CAKC;AAED,SAAgB,sBAAsB,CACpC,OAA8B;IAE9B,uBACE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AAO,SAAS,KAAK,QAAQ,CAAC,CAAC,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QAE1E,MAAM,IAAI,GAAG,wBAAwB,CAAC,OAAO,CAAC,CAAC;QAE/C,MAAM,MAAM,GAAG,MAAM,IAAA,gBAAS,EAAC,KAAK,EAAE,GAAG,EAAE;YACzC,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,UAAU,EAAE,CAAC,qBAAa,CAAC;YAC3B,QAAQ,EAAE,IAAI,CAAC,QAAQ;SACxB,CAAC,CAAC;QAEH,MAAM,OAAO,GAAG,MAAM,CAAC,OAAqB,CAAC;QAE7C,OAAO;YACL,EAAE,EAAE,OAAO,CAAC,GAAG;YACf,iBAAiB,EAAE,OAAO,CAAC,GAAG;YAC9B,qBAAqB,EAAE,OAAO,CAAC,GAAG;YAClC,KAAK,EAAE,OAAO,CAAC,GAAG;YAClB,WAAW,EAAE,OAAO,CAAC,IAAI;YACzB,gBAAgB,EAAE,OAAO,CAAC,GAAG,IAAI,IAAI;SACtC,CAAC;IACJ,CAAC;CAAA;AA1BD,8BA0BC;AAED,SAAgB,eAAe,CAC7B,OAAgB,EAChB,KAAwB;IAExB,MAAM,aAAa,GAAG,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IAClE,OAAO,aAAa,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;AACpE,CAAC;AAND,0CAMC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type { JWTPayload as LibPayload } from "jose
|
|
1
|
+
import type { JWTPayload as LibPayload } from "jose";
|
|
2
2
|
export interface JWTPayload extends LibPayload {
|
|
3
3
|
sub: string;
|
|
4
4
|
ref: string | null;
|
|
5
5
|
org: string;
|
|
6
6
|
rls: string[];
|
|
7
7
|
prms: string[];
|
|
8
|
-
|
|
8
|
+
seg: string | null;
|
|
9
9
|
}
|
|
10
10
|
export interface JWTUser {
|
|
11
11
|
id: string;
|
|
@@ -13,7 +13,7 @@ export interface JWTUser {
|
|
|
13
13
|
organizationReference: string;
|
|
14
14
|
roles: string[];
|
|
15
15
|
permissions: string[];
|
|
16
|
-
|
|
16
|
+
segmentReference: string | null;
|
|
17
17
|
}
|
|
18
18
|
export interface SignOptions {
|
|
19
19
|
issuer: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alanszp/jwt",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "10.0.0",
|
|
4
4
|
"description": "Alan's jwt validator & signer.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"typescript": "^4.3.4"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"jose": "^
|
|
27
|
+
"jose": "^5.2.2"
|
|
28
28
|
},
|
|
29
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "e06d4fec832847519814bcf472fdc9fff9ef0829"
|
|
30
30
|
}
|
package/src/jwt.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { createPublicKey, createPrivateKey, KeyObject } from "crypto";
|
|
2
|
-
import { SignJWT } from "jose
|
|
3
|
-
import { jwtVerify } from "jose/jwt/verify";
|
|
2
|
+
import { SignJWT, jwtVerify } from "jose";
|
|
4
3
|
import type { JWTPayload, JWTUser, SignOptions, VerifyOptions } from "./types";
|
|
5
4
|
|
|
6
5
|
export const JWT_ALGORITHM = "RS512";
|
|
@@ -66,7 +65,7 @@ export function createTokenPayload(user: JWTUser): JWTPayload {
|
|
|
66
65
|
org: user.organizationReference,
|
|
67
66
|
rls: user.roles,
|
|
68
67
|
prms: user.permissions,
|
|
69
|
-
|
|
68
|
+
seg: user.segmentReference,
|
|
70
69
|
};
|
|
71
70
|
}
|
|
72
71
|
|
|
@@ -94,7 +93,7 @@ export async function verifyJWT(
|
|
|
94
93
|
organizationReference: payload.org,
|
|
95
94
|
roles: payload.rls,
|
|
96
95
|
permissions: payload.prms,
|
|
97
|
-
|
|
96
|
+
segmentReference: payload.seg || null,
|
|
98
97
|
};
|
|
99
98
|
}
|
|
100
99
|
|
package/src/types.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { JWTPayload as LibPayload } from "jose
|
|
1
|
+
import type { JWTPayload as LibPayload } from "jose";
|
|
2
2
|
|
|
3
3
|
export interface JWTPayload extends LibPayload {
|
|
4
4
|
sub: string;
|
|
@@ -6,8 +6,8 @@ export interface JWTPayload extends LibPayload {
|
|
|
6
6
|
org: string;
|
|
7
7
|
rls: string[];
|
|
8
8
|
prms: string[];
|
|
9
|
-
//
|
|
10
|
-
|
|
9
|
+
// segmentReference
|
|
10
|
+
seg: string | null;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export interface JWTUser {
|
|
@@ -16,7 +16,7 @@ export interface JWTUser {
|
|
|
16
16
|
organizationReference: string;
|
|
17
17
|
roles: string[];
|
|
18
18
|
permissions: string[];
|
|
19
|
-
|
|
19
|
+
segmentReference: string | null;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
export interface SignOptions {
|