@toa.io/extensions.exposition 1.0.0-alpha.253 → 1.0.0-alpha.256
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/CHANGELOG.md +11 -0
- package/components/identity.bans/operations/tsconfig.tsbuildinfo +1 -1
- package/components/identity.basic/manifest.toa.yaml +1 -1
- package/components/identity.basic/operations/tsconfig.tsbuildinfo +1 -1
- package/components/identity.credentials/operations/tsconfig.tsbuildinfo +1 -1
- package/components/identity.federation/manifest.toa.yaml +4 -4
- package/components/identity.federation/operations/authenticate.js +2 -1
- package/components/identity.federation/operations/authenticate.js.map +1 -1
- package/components/identity.federation/operations/decode.js +2 -1
- package/components/identity.federation/operations/decode.js.map +1 -1
- package/components/identity.federation/operations/delete.d.ts +2 -2
- package/components/identity.federation/operations/delete.js +3 -3
- package/components/identity.federation/operations/delete.js.map +1 -1
- package/components/identity.federation/operations/incept.js +2 -1
- package/components/identity.federation/operations/incept.js.map +1 -1
- package/components/identity.federation/operations/lib/Ctx.d.ts +2 -0
- package/components/identity.federation/operations/lib/decode.js +4 -27
- package/components/identity.federation/operations/lib/decode.js.map +1 -1
- package/components/identity.federation/operations/lib/discovery.d.ts +4 -3
- package/components/identity.federation/operations/lib/discovery.js +21 -31
- package/components/identity.federation/operations/lib/discovery.js.map +1 -1
- package/components/identity.federation/operations/lib/exchange.js +7 -6
- package/components/identity.federation/operations/lib/exchange.js.map +1 -1
- package/components/identity.federation/operations/lib/jose.d.ts +41 -0
- package/components/identity.federation/operations/lib/jose.js +27 -0
- package/components/identity.federation/operations/lib/jose.js.map +1 -0
- package/components/identity.federation/operations/list.js +2 -1
- package/components/identity.federation/operations/list.js.map +1 -1
- package/components/identity.federation/operations/tsconfig.tsbuildinfo +1 -1
- package/components/identity.federation/operations/types/context.d.ts +2 -0
- package/components/identity.federation/source/authenticate.ts +2 -1
- package/components/identity.federation/source/decode.ts +2 -1
- package/components/identity.federation/source/delete.ts +4 -4
- package/components/identity.federation/source/incept.ts +2 -1
- package/components/identity.federation/source/lib/Ctx.ts +2 -0
- package/components/identity.federation/source/lib/decode.ts +4 -5
- package/components/identity.federation/source/lib/discovery.test.ts +45 -0
- package/components/identity.federation/source/lib/discovery.ts +27 -8
- package/components/identity.federation/source/lib/exchange.ts +7 -7
- package/components/identity.federation/source/lib/jose.d.ts +1 -0
- package/components/identity.federation/source/lib/jose.js +5 -0
- package/components/identity.federation/source/list.test.ts +2 -1
- package/components/identity.federation/source/list.ts +2 -1
- package/components/identity.federation/source/types/context.ts +3 -0
- package/components/identity.federation/tsconfig.json +1 -4
- package/components/identity.keys/manifest.toa.yaml +1 -0
- package/components/identity.keys/operations/create.js +2 -2
- package/components/identity.keys/operations/create.js.map +1 -1
- package/components/identity.keys/operations/tsconfig.tsbuildinfo +1 -1
- package/components/identity.keys/source/create.ts +2 -2
- package/components/identity.otp/operations/tsconfig.tsbuildinfo +1 -1
- package/components/identity.passkeys/operations/tsconfig.tsbuildinfo +1 -1
- package/components/identity.roles/operations/tsconfig.tsbuildinfo +1 -1
- package/components/identity.tokens/manifest.toa.yaml +21 -4
- package/components/identity.tokens/operations/decrypt.d.ts +4 -2
- package/components/identity.tokens/operations/decrypt.js +60 -12
- package/components/identity.tokens/operations/decrypt.js.map +1 -1
- package/components/identity.tokens/operations/encrypt.js +14 -13
- package/components/identity.tokens/operations/encrypt.js.map +1 -1
- package/components/identity.tokens/operations/lib/index.d.ts +1 -0
- package/components/identity.tokens/operations/lib/index.js +3 -0
- package/components/identity.tokens/operations/lib/index.js.map +1 -1
- package/components/identity.tokens/operations/lib/jose.d.ts +41 -0
- package/components/identity.tokens/operations/lib/jose.js +27 -0
- package/components/identity.tokens/operations/lib/jose.js.map +1 -0
- package/components/identity.tokens/operations/lib/key.d.ts +1 -0
- package/components/identity.tokens/operations/lib/key.js +11 -0
- package/components/identity.tokens/operations/lib/key.js.map +1 -0
- package/components/identity.tokens/operations/lib/types.d.ts +10 -1
- package/components/identity.tokens/operations/tsconfig.tsbuildinfo +1 -1
- package/components/identity.tokens/source/authenticate.test.ts +4 -3
- package/components/identity.tokens/source/decrypt.test.ts +69 -8
- package/components/identity.tokens/source/decrypt.ts +72 -14
- package/components/identity.tokens/source/encrypt.test.ts +30 -3
- package/components/identity.tokens/source/encrypt.ts +18 -16
- package/components/identity.tokens/source/lib/index.ts +1 -0
- package/components/identity.tokens/source/lib/jose.d.ts +1 -0
- package/components/identity.tokens/source/lib/jose.js +5 -0
- package/components/identity.tokens/source/lib/key.ts +8 -0
- package/components/identity.tokens/source/lib/types.ts +12 -1
- package/{components/context.toa.yaml → context.toa.yaml} +6 -2
- package/documentation/authorities.md +1 -1
- package/documentation/components.md +70 -30
- package/documentation/identity.md +12 -14
- package/features/access.feature +1 -1
- package/features/cache.feature +5 -5
- package/features/cors.feature +4 -4
- package/features/credentials.feature +3 -3
- package/features/identity.basic.feature +1 -1
- package/features/identity.federation.feature +4 -5
- package/features/identity.roles.feature +1 -1
- package/features/identity.tokens.feature +3 -3
- package/features/steps/Gateway.ts +11 -3
- package/package.json +18 -21
- package/source/HTTP/formats/yaml.test.ts +9 -0
- package/source/HTTP/formats/yaml.ts +2 -1
- package/source/HTTP/messages.ts +1 -1
- package/source/directives/io/lib/throttle/Interval.ts +10 -1
- package/transpiled/HTTP/formats/yaml.js +2 -1
- package/transpiled/HTTP/formats/yaml.js.map +1 -1
- package/transpiled/HTTP/messages.js +24 -4
- package/transpiled/HTTP/messages.js.map +1 -1
- package/transpiled/directives/io/lib/throttle/Interval.d.ts +1 -0
- package/transpiled/directives/io/lib/throttle/Interval.js +9 -1
- package/transpiled/directives/io/lib/throttle/Interval.js.map +1 -1
- package/transpiled/tsconfig.tsbuildinfo +1 -1
|
@@ -100,10 +100,26 @@ configuration:
|
|
|
100
100
|
type: object
|
|
101
101
|
properties:
|
|
102
102
|
keys:
|
|
103
|
-
type:
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
103
|
+
type: array
|
|
104
|
+
minItems: 1
|
|
105
|
+
contains:
|
|
106
|
+
properties:
|
|
107
|
+
format:
|
|
108
|
+
enum: [jwe]
|
|
109
|
+
items:
|
|
110
|
+
type: object
|
|
111
|
+
properties:
|
|
112
|
+
id:
|
|
113
|
+
type: string
|
|
114
|
+
minLength: 1
|
|
115
|
+
key:
|
|
116
|
+
type: string
|
|
117
|
+
format:
|
|
118
|
+
type: string
|
|
119
|
+
enum: [jwe, paseto]
|
|
120
|
+
default: jwe
|
|
121
|
+
required: [id, key]
|
|
122
|
+
additionalProperties: false
|
|
107
123
|
lifetime:
|
|
108
124
|
description: Token expiration time in seconds (default 30 days)
|
|
109
125
|
type: integer
|
|
@@ -122,6 +138,7 @@ configuration:
|
|
|
122
138
|
type: integer
|
|
123
139
|
default: 600000
|
|
124
140
|
default: {}
|
|
141
|
+
required: [keys]
|
|
125
142
|
|
|
126
143
|
exposition:
|
|
127
144
|
/:identity:
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import type { Maybe, Operation } from '@toa.io/types';
|
|
2
2
|
import type { Context, DecryptOutput } from './lib';
|
|
3
3
|
export declare class Computation implements Operation {
|
|
4
|
-
private keys;
|
|
4
|
+
private readonly keys;
|
|
5
|
+
private readonly legacy;
|
|
5
6
|
private cache;
|
|
6
7
|
private latest;
|
|
7
8
|
private remote;
|
|
8
9
|
private logs;
|
|
9
10
|
mount(context: Context): void;
|
|
10
11
|
execute(token: string): Promise<Maybe<DecryptOutput>>;
|
|
11
|
-
private
|
|
12
|
+
private pasetoKid;
|
|
13
|
+
private jweKid;
|
|
12
14
|
private key;
|
|
13
15
|
}
|
|
@@ -4,28 +4,39 @@ exports.Computation = void 0;
|
|
|
4
4
|
const paseto_1 = require("paseto");
|
|
5
5
|
const error_value_1 = require("error-value");
|
|
6
6
|
const lru_cache_1 = require("lru-cache");
|
|
7
|
+
const lib_1 = require("./lib");
|
|
8
|
+
const jose_1 = require("./lib/jose");
|
|
7
9
|
class Computation {
|
|
8
10
|
keys = {};
|
|
11
|
+
legacy = {};
|
|
9
12
|
cache;
|
|
10
13
|
latest;
|
|
11
14
|
remote;
|
|
12
15
|
logs;
|
|
13
16
|
mount(context) {
|
|
14
|
-
|
|
17
|
+
const latest = context.configuration.keys.find(({ format }) => format !== 'paseto');
|
|
18
|
+
if (latest === undefined)
|
|
19
|
+
throw new TypeError('At least one JWE key must be configured');
|
|
20
|
+
this.latest = latest.id;
|
|
15
21
|
this.remote = context.remote.identity.keys;
|
|
16
22
|
this.cache = new lru_cache_1.LRUCache(context.configuration.cache);
|
|
17
23
|
this.logs = context.logs;
|
|
18
|
-
for (const
|
|
19
|
-
|
|
24
|
+
for (const { id, key, format } of context.configuration.keys) {
|
|
25
|
+
const branch = format === 'paseto' ? this.legacy : this.keys;
|
|
26
|
+
branch[id] = { key };
|
|
27
|
+
}
|
|
20
28
|
}
|
|
21
29
|
async execute(token) {
|
|
22
|
-
const
|
|
30
|
+
const legacy = token.startsWith('v3.local.');
|
|
31
|
+
const kid = legacy ? this.pasetoKid(token) : await this.jweKid(token);
|
|
23
32
|
if (kid instanceof Error)
|
|
24
33
|
return kid;
|
|
25
|
-
const key = await this.key(kid);
|
|
34
|
+
const key = await this.key(kid, legacy);
|
|
26
35
|
if (key instanceof Error)
|
|
27
36
|
return key;
|
|
28
|
-
const claims =
|
|
37
|
+
const claims = legacy
|
|
38
|
+
? await decryptPaseto(token, key.key)
|
|
39
|
+
: await decryptJWE(token, key.key);
|
|
29
40
|
if (claims instanceof Error)
|
|
30
41
|
return claims;
|
|
31
42
|
this.logs.debug('Token claims', claims);
|
|
@@ -36,10 +47,10 @@ class Computation {
|
|
|
36
47
|
iat: claims.iat,
|
|
37
48
|
exp: claims.exp,
|
|
38
49
|
identity: claims.identity,
|
|
39
|
-
refresh: kid !== this.latest && key.identity === undefined
|
|
50
|
+
refresh: legacy || (kid !== this.latest && key.identity === undefined)
|
|
40
51
|
};
|
|
41
52
|
}
|
|
42
|
-
|
|
53
|
+
pasetoKid(token) {
|
|
43
54
|
const [, , , footer] = token.split('.');
|
|
44
55
|
if (footer === undefined)
|
|
45
56
|
return ERR_INVALID_TOKEN;
|
|
@@ -54,9 +65,23 @@ class Computation {
|
|
|
54
65
|
return ERR_INVALID_TOKEN;
|
|
55
66
|
}
|
|
56
67
|
}
|
|
57
|
-
async
|
|
58
|
-
|
|
59
|
-
|
|
68
|
+
async jweKid(token) {
|
|
69
|
+
try {
|
|
70
|
+
const { decodeProtectedHeader } = await (0, jose_1.load)();
|
|
71
|
+
const header = decodeProtectedHeader(token);
|
|
72
|
+
if (header.alg !== 'dir' || header.enc !== 'A256GCM' || header.typ !== 'JWT' ||
|
|
73
|
+
typeof header.kid !== 'string')
|
|
74
|
+
return ERR_INVALID_TOKEN;
|
|
75
|
+
return header.kid;
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
return ERR_INVALID_TOKEN;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
async key(kid, legacy) {
|
|
82
|
+
const configured = legacy ? this.legacy : this.keys;
|
|
83
|
+
if (kid in configured)
|
|
84
|
+
return configured[kid];
|
|
60
85
|
if (!this.cache.has(kid)) {
|
|
61
86
|
const value = await this.remote.observe({ query: { id: kid } });
|
|
62
87
|
this.cache.set(kid, { value });
|
|
@@ -66,7 +91,7 @@ class Computation {
|
|
|
66
91
|
}
|
|
67
92
|
}
|
|
68
93
|
exports.Computation = Computation;
|
|
69
|
-
async function
|
|
94
|
+
async function decryptPaseto(token, key) {
|
|
70
95
|
try {
|
|
71
96
|
return await paseto_1.V3.decrypt(token, key);
|
|
72
97
|
}
|
|
@@ -74,6 +99,29 @@ async function decrypt(token, key) {
|
|
|
74
99
|
return ERR_INVALID_TOKEN;
|
|
75
100
|
}
|
|
76
101
|
}
|
|
102
|
+
async function decryptJWE(token, key) {
|
|
103
|
+
try {
|
|
104
|
+
const { jwtDecrypt } = await (0, jose_1.load)();
|
|
105
|
+
const { payload } = await jwtDecrypt(token, (0, lib_1.jweKey)(key), {
|
|
106
|
+
keyManagementAlgorithms: ['dir'],
|
|
107
|
+
contentEncryptionAlgorithms: ['A256GCM']
|
|
108
|
+
});
|
|
109
|
+
if (typeof payload.iss !== 'string' || typeof payload.iat !== 'number' ||
|
|
110
|
+
typeof payload.identity !== 'object' || payload.identity === null)
|
|
111
|
+
return ERR_INVALID_TOKEN;
|
|
112
|
+
if (payload.exp !== undefined && payload.exp * 1000 <= Date.now())
|
|
113
|
+
return ERR_INVALID_TOKEN;
|
|
114
|
+
return {
|
|
115
|
+
iss: payload.iss,
|
|
116
|
+
iat: new Date(payload.iat * 1000).toISOString(),
|
|
117
|
+
...(payload.exp === undefined ? {} : { exp: new Date(payload.exp * 1000).toISOString() }),
|
|
118
|
+
identity: payload.identity
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
catch {
|
|
122
|
+
return ERR_INVALID_TOKEN;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
77
125
|
const ERR_INVALID_TOKEN = new error_value_1.Err('INVALID_TOKEN');
|
|
78
126
|
const ERR_INVALID_KEY = new error_value_1.Err('INVALID_KEY');
|
|
79
127
|
const ERR_FORGED_KEY = new error_value_1.Err('FORGED_KEY');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decrypt.js","sourceRoot":"","sources":["../source/decrypt.ts"],"names":[],"mappings":";;;AAAA,mCAA2B;AAC3B,6CAAiC;AACjC,yCAAoC;
|
|
1
|
+
{"version":3,"file":"decrypt.js","sourceRoot":"","sources":["../source/decrypt.ts"],"names":[],"mappings":";;;AAAA,mCAA2B;AAC3B,6CAAiC;AACjC,yCAAoC;AACpC,+BAA8B;AAC9B,qCAAiC;AAIjC,MAAa,WAAW;IACL,IAAI,GAAwB,EAAE,CAAA;IAC9B,MAAM,GAAwB,EAAE,CAAA;IACzC,KAAK,CAA6B;IAClC,MAAM,CAAS;IACf,MAAM,CAAwC;IAC9C,IAAI,CAAkB;IAEvB,KAAK,CAAE,OAAgB;QAC5B,MAAM,MAAM,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,WAAW,EAAE,EAAE,CAAC;YACzF,QAAQ,EAAE,OAAO,CAAC,QAAQ;SAC3B,CAAA;IACH,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,iBAAiB,CAAA;IAC1B,CAAC;AACH,CAAC;AAWD,MAAM,iBAAiB,GAAG,IAAI,iBAAG,CAAC,eAAe,CAAC,CAAA;AAClD,MAAM,eAAe,GAAG,IAAI,iBAAG,CAAC,aAAa,CAAC,CAAA;AAC9C,MAAM,cAAc,GAAG,IAAI,iBAAG,CAAC,YAAY,CAAC,CAAA"}
|
|
@@ -1,37 +1,38 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Effect = void 0;
|
|
4
|
-
const paseto_1 = require("paseto");
|
|
5
4
|
const error_value_1 = require("error-value");
|
|
5
|
+
const lib_1 = require("./lib");
|
|
6
|
+
const jose_1 = require("./lib/jose");
|
|
6
7
|
class Effect {
|
|
7
8
|
key;
|
|
8
9
|
lifetime;
|
|
9
10
|
mount(context) {
|
|
10
|
-
const
|
|
11
|
-
|
|
11
|
+
const key = context.configuration.keys.find(({ format }) => format !== 'paseto');
|
|
12
|
+
if (key === undefined)
|
|
13
|
+
throw new TypeError('At least one JWE key must be configured');
|
|
14
|
+
this.key = key;
|
|
12
15
|
this.lifetime = context.configuration.lifetime * 1000;
|
|
13
16
|
}
|
|
14
17
|
async execute(input) {
|
|
18
|
+
const { EncryptJWT } = await (0, jose_1.load)();
|
|
15
19
|
if (input.scopes?.some((scope) => !within(scope, input.identity.roles)) === true)
|
|
16
20
|
return ERR_INACCESSIBLE_SCOPE;
|
|
17
21
|
const lifetime = input.lifetime === undefined ? this.lifetime : (input.lifetime * 1000);
|
|
18
|
-
const exp = lifetime === 0
|
|
19
|
-
? undefined
|
|
20
|
-
: new Date(Date.now() + lifetime).toISOString();
|
|
21
22
|
const identity = {
|
|
22
23
|
id: input.identity.id,
|
|
23
24
|
roles: input.scopes ?? input.identity.roles
|
|
24
25
|
};
|
|
25
26
|
if (input.permissions !== undefined)
|
|
26
27
|
identity.permissions = input.permissions;
|
|
27
|
-
const payload = {
|
|
28
|
-
identity,
|
|
29
|
-
iss: input.authority
|
|
30
|
-
};
|
|
31
|
-
if (exp !== undefined)
|
|
32
|
-
payload.exp = exp;
|
|
33
28
|
const key = input.key ?? this.key;
|
|
34
|
-
|
|
29
|
+
let token = new EncryptJWT({ identity })
|
|
30
|
+
.setProtectedHeader({ alg: 'dir', enc: 'A256GCM', typ: 'JWT', kid: key.id })
|
|
31
|
+
.setIssuer(input.authority)
|
|
32
|
+
.setIssuedAt(Date.now() / 1000);
|
|
33
|
+
if (lifetime !== 0)
|
|
34
|
+
token = token.setExpirationTime((Date.now() + lifetime) / 1000);
|
|
35
|
+
return await token.encrypt((0, lib_1.jweKey)(key.key));
|
|
35
36
|
}
|
|
36
37
|
}
|
|
37
38
|
exports.Effect = Effect;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encrypt.js","sourceRoot":"","sources":["../source/encrypt.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"encrypt.js","sourceRoot":"","sources":["../source/encrypt.ts"],"names":[],"mappings":";;;AAAA,6CAAiC;AACjC,+BAA8B;AAC9B,qCAAiC;AAIjC,MAAa,MAAM;IACT,GAAG,CAA0B;IAC7B,QAAQ,CAAS;IAElB,KAAK,CAAE,OAAgB;QAC5B,MAAM,GAAG,GAAG,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,MAAM,KAAK,QAAQ,CAAC,CAAA;QAEhF,IAAI,GAAG,KAAK,SAAS;YACnB,MAAM,IAAI,SAAS,CAAC,yCAAyC,CAAC,CAAA;QAEhE,IAAI,CAAC,GAAG,GAAG,GAAG,CAAA;QACd,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,aAAa,CAAC,QAAQ,GAAG,IA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,EAAE,GAAG,QAAQ,CAAC,GAAG,IAAI,CAAC,CAAA;QAEjE,OAAO,MAAM,KAAK,CAAC,OAAO,CAAC,IAAA,YAAM,EAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAA;IAC7C,CAAC;CACF;AA1CD,wBA0CC;AAED,SAAS,MAAM,CAAE,KAAa,EAAE,KAAe;IAC7C,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAK,KAAK,IAAI,KAAK,CAAC,UAAU,CAAC,IAAI,GAAG,GAAG,CAAC,CAAC,CAAA;AAC7E,CAAC;AAED,MAAM,sBAAsB,GAAG,IAAI,iBAAG,CAAC,oBAAoB,CAAC,CAAA"}
|
|
@@ -14,6 +14,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.jweKey = void 0;
|
|
17
18
|
__exportStar(require("./pad"), exports);
|
|
18
19
|
__exportStar(require("./types"), exports);
|
|
20
|
+
var key_1 = require("./key");
|
|
21
|
+
Object.defineProperty(exports, "jweKey", { enumerable: true, get: function () { return key_1.jweKey; } });
|
|
19
22
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/lib/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/lib/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,wCAAqB;AACrB,0CAAuB;AACvB,6BAA8B;AAArB,6FAAA,MAAM,OAAA"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export function load(): Promise<{
|
|
2
|
+
default: typeof import("jose");
|
|
3
|
+
compactDecrypt: typeof import("jose").compactDecrypt;
|
|
4
|
+
flattenedDecrypt: typeof import("jose").flattenedDecrypt;
|
|
5
|
+
generalDecrypt: typeof import("jose").generalDecrypt;
|
|
6
|
+
GeneralEncrypt: typeof import("jose").GeneralEncrypt;
|
|
7
|
+
compactVerify: typeof import("jose").compactVerify;
|
|
8
|
+
flattenedVerify: typeof import("jose").flattenedVerify;
|
|
9
|
+
generalVerify: typeof import("jose").generalVerify;
|
|
10
|
+
jwtVerify: typeof import("jose").jwtVerify;
|
|
11
|
+
jwtDecrypt: typeof import("jose").jwtDecrypt;
|
|
12
|
+
CompactEncrypt: typeof import("jose").CompactEncrypt;
|
|
13
|
+
FlattenedEncrypt: typeof import("jose").FlattenedEncrypt;
|
|
14
|
+
CompactSign: typeof import("jose").CompactSign;
|
|
15
|
+
FlattenedSign: typeof import("jose").FlattenedSign;
|
|
16
|
+
GeneralSign: typeof import("jose").GeneralSign;
|
|
17
|
+
SignJWT: typeof import("jose").SignJWT;
|
|
18
|
+
EncryptJWT: typeof import("jose").EncryptJWT;
|
|
19
|
+
calculateJwkThumbprint: typeof import("jose").calculateJwkThumbprint;
|
|
20
|
+
calculateJwkThumbprintUri: typeof import("jose").calculateJwkThumbprintUri;
|
|
21
|
+
EmbeddedJWK: typeof import("jose").EmbeddedJWK;
|
|
22
|
+
createLocalJWKSet: typeof import("jose").createLocalJWKSet;
|
|
23
|
+
createRemoteJWKSet: typeof import("jose").createRemoteJWKSet;
|
|
24
|
+
jwksCache: typeof import("jose").jwksCache;
|
|
25
|
+
customFetch: typeof import("jose").customFetch;
|
|
26
|
+
UnsecuredJWT: typeof import("jose").UnsecuredJWT;
|
|
27
|
+
exportPKCS8: typeof import("jose").exportPKCS8;
|
|
28
|
+
exportSPKI: typeof import("jose").exportSPKI;
|
|
29
|
+
exportJWK: typeof import("jose").exportJWK;
|
|
30
|
+
importSPKI: typeof import("jose").importSPKI;
|
|
31
|
+
importPKCS8: typeof import("jose").importPKCS8;
|
|
32
|
+
importX509: typeof import("jose").importX509;
|
|
33
|
+
importJWK: typeof import("jose").importJWK;
|
|
34
|
+
decodeProtectedHeader: typeof import("jose").decodeProtectedHeader;
|
|
35
|
+
decodeJwt: typeof import("jose").decodeJwt;
|
|
36
|
+
errors: typeof import("jose/dist/types/util/errors");
|
|
37
|
+
generateKeyPair: typeof import("jose").generateKeyPair;
|
|
38
|
+
generateSecret: typeof import("jose").generateSecret;
|
|
39
|
+
base64url: typeof import("jose/dist/types/util/base64url");
|
|
40
|
+
cryptoRuntime: "WebCryptoAPI";
|
|
41
|
+
}>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
const load = async () => await Promise.resolve().then(() => __importStar(require('jose')));
|
|
26
|
+
exports.load = load;
|
|
27
|
+
//# sourceMappingURL=jose.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jose.js","sourceRoot":"","sources":["../../source/lib/jose.js"],"names":[],"mappings":"AAAA,YAAY,CAAA;;;;;;;;;;;;;;;;;;;;;;;;AAEZ,MAAM,IAAI,GAAG,KAAK,IAAI,EAAE,CAAC,wDAAa,MAAM,GAAC,CAAA;AAE7C,OAAO,CAAC,IAAI,GAAG,IAAI,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function jweKey(value: string): Uint8Array;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.jweKey = void 0;
|
|
4
|
+
function jweKey(value) {
|
|
5
|
+
const key = Buffer.from(value, 'base64url');
|
|
6
|
+
if (key.length !== 32 || key.toString('base64url') !== value)
|
|
7
|
+
throw new TypeError('JWE key must be a base64url-encoded 256-bit secret');
|
|
8
|
+
return new Uint8Array(key);
|
|
9
|
+
}
|
|
10
|
+
exports.jweKey = jweKey;
|
|
11
|
+
//# sourceMappingURL=key.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"key.js","sourceRoot":"","sources":["../../source/lib/key.ts"],"names":[],"mappings":";;;AAAA,SAAgB,MAAM,CAAE,KAAa;IACnC,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,WAAW,CAAC,CAAA;IAE3C,IAAI,GAAG,CAAC,MAAM,KAAK,EAAE,IAAI,GAAG,CAAC,QAAQ,CAAC,WAAW,CAAC,KAAK,KAAK;QAC1D,MAAM,IAAI,SAAS,CAAC,oDAAoD,CAAC,CAAA;IAE3E,OAAO,IAAI,UAAU,CAAC,GAAG,CAAC,CAAA;AAC5B,CAAC;AAPD,wBAOC"}
|
|
@@ -20,7 +20,7 @@ export interface Context {
|
|
|
20
20
|
logs: telemetry.Logs;
|
|
21
21
|
}
|
|
22
22
|
export interface Configuration {
|
|
23
|
-
readonly keys:
|
|
23
|
+
readonly keys: ConfiguredKey[];
|
|
24
24
|
readonly lifetime: number;
|
|
25
25
|
readonly refresh: number;
|
|
26
26
|
readonly cache: {
|
|
@@ -28,6 +28,9 @@ export interface Configuration {
|
|
|
28
28
|
ttl: number;
|
|
29
29
|
};
|
|
30
30
|
}
|
|
31
|
+
export interface ConfiguredKey extends Pick<Key, 'id' | 'key'> {
|
|
32
|
+
format?: 'jwe' | 'paseto';
|
|
33
|
+
}
|
|
31
34
|
export interface Entity {
|
|
32
35
|
revokedAt?: number;
|
|
33
36
|
}
|
|
@@ -65,6 +68,12 @@ export interface Claims {
|
|
|
65
68
|
iat: string;
|
|
66
69
|
exp?: string;
|
|
67
70
|
}
|
|
71
|
+
export interface JWEClaims {
|
|
72
|
+
identity: Identity;
|
|
73
|
+
iss: string;
|
|
74
|
+
iat: number;
|
|
75
|
+
exp?: number;
|
|
76
|
+
}
|
|
68
77
|
export interface Key {
|
|
69
78
|
id: string;
|
|
70
79
|
key: string;
|