@kaapi/oauth2-auth-design 0.0.35 → 0.0.36

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.
@@ -0,0 +1,240 @@
1
+ "use strict";
2
+ var _OAuth2UtilGenerator_instances, _OAuth2UtilGenerator_values, _OAuth2UtilGenerator_getDpopReplayDetectorContent, _OAuth2UtilGenerator_getJwksKeyStoreContent, _OAuth2UtilGenerator_getJwksRotationTimestampStoreContent;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.OAuth2UtilGenerator = void 0;
5
+ const tslib_1 = require("tslib");
6
+ const definitions_1 = require("@kaapi/cli/definitions");
7
+ const utils_1 = require("@kaapi/cli/utils");
8
+ var KIND_ENUM;
9
+ (function (KIND_ENUM) {
10
+ KIND_ENUM["dpopReplayDetector"] = "dpop-replay-detector";
11
+ KIND_ENUM["jwksKeyStore"] = "jwks-key-store";
12
+ KIND_ENUM["jwksRotationTimestampStore"] = "jwks-rotation-timestamp-store";
13
+ })(KIND_ENUM || (KIND_ENUM = {}));
14
+ const KIND_OPTIONS = [
15
+ {
16
+ value: KIND_ENUM.dpopReplayDetector,
17
+ label: 'DPoP Replay Detector',
18
+ hint: ''
19
+ },
20
+ {
21
+ value: KIND_ENUM.jwksKeyStore,
22
+ label: 'Jwks Key Store',
23
+ hint: ''
24
+ },
25
+ {
26
+ value: KIND_ENUM.jwksRotationTimestampStore,
27
+ label: 'Jwks Rotation Timestamp Store',
28
+ hint: ''
29
+ },
30
+ ];
31
+ class OAuth2UtilGenerator {
32
+ constructor() {
33
+ _OAuth2UtilGenerator_instances.add(this);
34
+ _OAuth2UtilGenerator_values.set(this, {
35
+ name: '',
36
+ kind: ''
37
+ });
38
+ }
39
+ get type() {
40
+ return 'others';
41
+ }
42
+ get name() {
43
+ return 'oauth2-util';
44
+ }
45
+ get description() {
46
+ return 'Creates util.';
47
+ }
48
+ get notes() {
49
+ return [
50
+ 'Allowed values for --kind:',
51
+ ...KIND_OPTIONS.map(o => ` - ${o.value}`)
52
+ ];
53
+ }
54
+ get options() {
55
+ return {
56
+ name: 'The name',
57
+ kind: 'The kind'
58
+ };
59
+ }
60
+ init(options) {
61
+ if (typeof options['name'] == 'string') {
62
+ tslib_1.__classPrivateFieldGet(this, _OAuth2UtilGenerator_values, "f").name = (0, utils_1.camelCase)(options['name']);
63
+ }
64
+ if (typeof options['kind'] == 'string') {
65
+ if (!KIND_OPTIONS.map(v => v.value).includes(options['kind'])) {
66
+ throw new Error(`Invalid value for '--kind'. Allowed values are: ${KIND_OPTIONS.map(v => v.value).join(', ')}.`);
67
+ }
68
+ tslib_1.__classPrivateFieldGet(this, _OAuth2UtilGenerator_values, "f").kind = options['kind'];
69
+ }
70
+ }
71
+ isValid() {
72
+ return !!(tslib_1.__classPrivateFieldGet(this, _OAuth2UtilGenerator_values, "f").name && tslib_1.__classPrivateFieldGet(this, _OAuth2UtilGenerator_values, "f").kind);
73
+ }
74
+ getFileContent() {
75
+ if (tslib_1.__classPrivateFieldGet(this, _OAuth2UtilGenerator_values, "f").kind === KIND_ENUM.dpopReplayDetector)
76
+ return tslib_1.__classPrivateFieldGet(this, _OAuth2UtilGenerator_instances, "m", _OAuth2UtilGenerator_getDpopReplayDetectorContent).call(this);
77
+ else if (tslib_1.__classPrivateFieldGet(this, _OAuth2UtilGenerator_values, "f").kind === KIND_ENUM.jwksKeyStore)
78
+ return tslib_1.__classPrivateFieldGet(this, _OAuth2UtilGenerator_instances, "m", _OAuth2UtilGenerator_getJwksKeyStoreContent).call(this);
79
+ else if (tslib_1.__classPrivateFieldGet(this, _OAuth2UtilGenerator_values, "f").kind === KIND_ENUM.jwksRotationTimestampStore)
80
+ return tslib_1.__classPrivateFieldGet(this, _OAuth2UtilGenerator_instances, "m", _OAuth2UtilGenerator_getJwksRotationTimestampStoreContent).call(this);
81
+ else
82
+ return '';
83
+ }
84
+ getQuestions() {
85
+ const r = [];
86
+ if (!(tslib_1.__classPrivateFieldGet(this, _OAuth2UtilGenerator_values, "f").kind && KIND_OPTIONS.map(v => v.value).includes(tslib_1.__classPrivateFieldGet(this, _OAuth2UtilGenerator_values, "f").kind))) {
87
+ r.push({
88
+ type: definitions_1.QuestionType.select,
89
+ options: {
90
+ message: 'The kind?',
91
+ options: KIND_OPTIONS
92
+ },
93
+ setValue: (value) => {
94
+ tslib_1.__classPrivateFieldGet(this, _OAuth2UtilGenerator_values, "f").kind = `${value}`;
95
+ }
96
+ });
97
+ }
98
+ if (!tslib_1.__classPrivateFieldGet(this, _OAuth2UtilGenerator_values, "f").name) {
99
+ const camelCasedType = (0, utils_1.camelCase)(tslib_1.__classPrivateFieldGet(this, _OAuth2UtilGenerator_values, "f").kind || 'custom-util');
100
+ r.push({
101
+ type: definitions_1.QuestionType.text,
102
+ options: {
103
+ message: 'The name?',
104
+ defaultValue: camelCasedType,
105
+ placeholder: camelCasedType
106
+ },
107
+ setValue: (pluginName) => {
108
+ tslib_1.__classPrivateFieldGet(this, _OAuth2UtilGenerator_values, "f").name = (0, utils_1.camelCase)(pluginName);
109
+ }
110
+ });
111
+ }
112
+ return r;
113
+ }
114
+ getFilename() {
115
+ return (0, utils_1.kebabCase)(`${tslib_1.__classPrivateFieldGet(this, _OAuth2UtilGenerator_values, "f").name}`) + '.ts';
116
+ }
117
+ }
118
+ exports.OAuth2UtilGenerator = OAuth2UtilGenerator;
119
+ _OAuth2UtilGenerator_values = new WeakMap(), _OAuth2UtilGenerator_instances = new WeakSet(), _OAuth2UtilGenerator_getDpopReplayDetectorContent = function _OAuth2UtilGenerator_getDpopReplayDetectorContent() {
120
+ return `// generated by @kaapi/oauth2-auth-design
121
+
122
+ import { ReplayDetector } from '@kaapi/oauth2-auth-design'
123
+
124
+ /**
125
+ * A custom implementation of a DPoP (Demonstration of Proof-of-Possession) replay detector.
126
+ * Provides methods to track and prevent replay attacks by storing and checking unique values
127
+ * with a defined time-to-live.
128
+ */
129
+ export const ${tslib_1.__classPrivateFieldGet(this, _OAuth2UtilGenerator_values, "f").name}: ReplayDetector = {
130
+ /**
131
+ * Checks whether a given value has already been seen (i.e., replayed).
132
+ *
133
+ * @param {string} value - The unique identifier to check for replay.
134
+ * @returns {Promise<boolean>} A promise that resolves to \`true\` if the value exists
135
+ * (indicating a replay), or \`false\` if it has not been seen before.
136
+ */
137
+ has(value: string): Promise<boolean> {
138
+ throw new Error('Method not implemented.');
139
+ },
140
+
141
+ /**
142
+ * Deletes a previously stored value from the replay detector.
143
+ *
144
+ * @param {string} value - The unique identifier to remove from storage.
145
+ * @returns {Promise<void>} A promise that resolves when the value has been deleted.
146
+ */
147
+ delete(value: string): Promise<void> {
148
+ throw new Error('Method not implemented.');
149
+ },
150
+
151
+ /**
152
+ * Adds a new value to the replay detector with a specified time-to-live.
153
+ *
154
+ * @param {string} value - The unique identifier to store for replay detection.
155
+ * @param {number} ttlSeconds - The time-to-live in seconds, after which the value expires.
156
+ * @returns {Promise<void>} A promise that resolves when the value has been stored.
157
+ */
158
+ add(value: string, ttlSeconds: number): Promise<void> {
159
+ throw new Error('Method not implemented.');
160
+ }
161
+ };
162
+ `;
163
+ }, _OAuth2UtilGenerator_getJwksKeyStoreContent = function _OAuth2UtilGenerator_getJwksKeyStoreContent() {
164
+ return `// generated by @kaapi/oauth2-auth-design
165
+
166
+ import { JwksKeyStore } from '@kaapi/oauth2-auth-design';
167
+
168
+ /**
169
+ * A custom implementation of a JSON Web Key Store (JWKS).
170
+ * Provides methods to store and retrieve key pairs used for signing and verifying JWTs.
171
+ */
172
+ export const ${tslib_1.__classPrivateFieldGet(this, _OAuth2UtilGenerator_values, "f").name}: JwksKeyStore = {
173
+ /**
174
+ * Stores a key pair (private and public keys) in the JWKS with a given key ID and time-to-live.
175
+ *
176
+ * @param {string} kid - The Key ID (KID) used to uniquely identify the key pair.
177
+ * @param {object} privateKey - The private key object used for signing tokens.
178
+ * @param {object} publicKey - The public key object used for verifying tokens.
179
+ * @param {number} ttl - The time-to-live (in seconds) for how long the key pair should remain valid.
180
+ * @returns {void | Promise<void>} Returns nothing or a promise that resolves when the key pair is stored.
181
+ */
182
+ storeKeyPair(kid: string, privateKey: object, publicKey: object, ttl: number): void | Promise<void> {
183
+ throw new Error('Function not implemented.');
184
+ },
185
+
186
+ /**
187
+ * Retrieves the private key currently stored in the JWKS.
188
+ *
189
+ * @returns {Promise<object | undefined>} A promise that resolves to the private key object,
190
+ * or \`undefined\` if no private key is available.
191
+ */
192
+ getPrivateKey(): Promise<object | undefined> {
193
+ throw new Error('Function not implemented.');
194
+ },
195
+
196
+ /**
197
+ * Retrieves all public keys currently stored in the JWKS.
198
+ *
199
+ * @returns {Promise<object[]>} A promise that resolves to an array of public key objects.
200
+ */
201
+ getPublicKeys(): Promise<object[]> {
202
+ throw new Error('Function not implemented.');
203
+ }
204
+ };
205
+ `;
206
+ }, _OAuth2UtilGenerator_getJwksRotationTimestampStoreContent = function _OAuth2UtilGenerator_getJwksRotationTimestampStoreContent() {
207
+ return `// generated by @kaapi/oauth2-auth-design
208
+
209
+ import { JwksRotationTimestampStore } from '@kaapi/oauth2-auth-design';
210
+
211
+ /**
212
+ * A custom implementation of a JWKS rotation timestamp store.
213
+ * Provides methods to persist and retrieve the last rotation timestamp
214
+ * for JSON Web Key Sets (JWKS).
215
+ */
216
+ export const ${tslib_1.__classPrivateFieldGet(this, _OAuth2UtilGenerator_values, "f").name}: JwksRotationTimestampStore = {
217
+ /**
218
+ * Retrieves the timestamp of the last JWKS rotation.
219
+ *
220
+ * @returns {Promise<number>} A promise that resolves to the last rotation timestamp
221
+ * in milliseconds since the Unix epoch.
222
+ */
223
+ getLastRotationTimestamp: function (): Promise<number> {
224
+ throw new Error('Function not implemented.');
225
+ },
226
+
227
+ /**
228
+ * Sets the timestamp of the last JWKS rotation.
229
+ *
230
+ * @param {number} rotationTimestamp - The rotation timestamp to store,
231
+ * expressed in milliseconds since the Unix epoch.
232
+ * @returns {Promise<void>} A promise that resolves when the timestamp has been stored.
233
+ */
234
+ setLastRotationTimestamp: function (rotationTimestamp: number): Promise<void> {
235
+ throw new Error('Function not implemented.');
236
+ }
237
+ };
238
+ `;
239
+ };
240
+ //# sourceMappingURL=oauth2-util-generator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oauth2-util-generator.js","sourceRoot":"","sources":["../../src/generators/oauth2-util-generator.ts"],"names":[],"mappings":";;;;;AAAA,wDAAiG;AACjG,4CAAuD;AAEvD,IAAK,SAIJ;AAJD,WAAK,SAAS;IACV,wDAA2C,CAAA;IAC3C,4CAA+B,CAAA;IAC/B,yEAA4D,CAAA;AAChE,CAAC,EAJI,SAAS,KAAT,SAAS,QAIb;AAED,MAAM,YAAY,GAIZ;IACE;QACI,KAAK,EAAE,SAAS,CAAC,kBAAkB;QACnC,KAAK,EAAE,sBAAsB;QAC7B,IAAI,EAAE,EAAE;KACX;IACD;QACI,KAAK,EAAE,SAAS,CAAC,YAAY;QAC7B,KAAK,EAAE,gBAAgB;QACvB,IAAI,EAAE,EAAE;KACX;IACD;QACI,KAAK,EAAE,SAAS,CAAC,0BAA0B;QAC3C,KAAK,EAAE,+BAA+B;QACtC,IAAI,EAAE,EAAE;KACX;CACJ,CAAC;AAEN,MAAa,mBAAmB;IAAhC;;QA4BI,sCAAU;YACN,IAAI,EAAE,EAAE;YACR,IAAI,EAAE,EAAE;SACX,EAAA;IAgML,CAAC;IA7NG,IAAI,IAAI;QACJ,OAAO,QAAQ,CAAA;IACnB,CAAC;IAED,IAAI,IAAI;QACJ,OAAO,aAAa,CAAA;IACxB,CAAC;IAED,IAAI,WAAW;QACX,OAAO,eAAe,CAAA;IAC1B,CAAC;IAED,IAAI,KAAK;QACL,OAAO;YACH,4BAA4B;YAC5B,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,CAAC;SAC7C,CAAA;IACL,CAAC;IAED,IAAI,OAAO;QACP,OAAO;YACH,IAAI,EAAE,UAAU;YAChB,IAAI,EAAE,UAAU;S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,CAAC,IAAI,EAAE,CAAC,GAAG,KAAK,CAAA;IACpD,CAAC;CA+HJ;AA/ND,kDA+NC;;IA5HO,OAAO;;;;;;;;;eASA,+BAAA,IAAI,mCAAQ,CAAC,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiC/B,CAAA;AACG,CAAC;IAGG,OAAO;;;;;;;;eAQA,+BAAA,IAAI,mCAAQ,CAAC,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiC/B,CAAA;AACG,CAAC;IAGG,OAAO;;;;;;;;;eASA,+BAAA,IAAI,mCAAQ,CAAC,IAAI;;;;;;;;;;;;;;;;;;;;;;CAsB/B,CAAA;AACG,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kaapi/oauth2-auth-design",
3
- "version": "0.0.35",
3
+ "version": "0.0.36",
4
4
  "private": false,
5
5
  "description": "OAuth2 auth design for kaapi",
6
6
  "main": "lib/index.js",
@@ -37,18 +37,18 @@
37
37
  "@hapi/hoek": "^11.0.7",
38
38
  "@novice1/api-doc-generator": "^1.2.5",
39
39
  "html-entities": "^2.6.0",
40
- "jose": "^6.0.13",
40
+ "jose": "^6.1.3",
41
41
  "jwk-to-pem": "^2.0.7",
42
42
  "node-jose": "^2.2.0",
43
43
  "tslib": "^2.8.1",
44
- "@kaapi/cli": "^0.0.35",
45
- "@kaapi/kaapi": "^0.0.35"
44
+ "@kaapi/cli": "^0.0.36",
45
+ "@kaapi/kaapi": "^0.0.36"
46
46
  },
47
47
  "devDependencies": {
48
48
  "@types/jwk-to-pem": "^2.0.3",
49
49
  "@types/mocha": "^10.0.10",
50
50
  "@types/node-jose": "^1.1.13",
51
- "uuid": "^11.1.0"
51
+ "uuid": "^13.0.0"
52
52
  },
53
53
  "scripts": {
54
54
  "lint": "eslint .",