@tsed/oidc-provider 7.14.1 → 7.14.2
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/lib/cjs/index.js +1 -0
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/services/OidcProvider.js +31 -0
- package/lib/cjs/services/OidcProvider.js.map +1 -1
- package/lib/cjs/utils/events.js +61 -0
- package/lib/cjs/utils/events.js.map +1 -0
- package/lib/esm/index.js +1 -0
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/services/OidcProvider.js +32 -1
- package/lib/esm/services/OidcProvider.js.map +1 -1
- package/lib/esm/utils/events.js +58 -0
- package/lib/esm/utils/events.js.map +1 -0
- package/lib/types/index.d.ts +1 -0
- package/lib/types/services/OidcProvider.d.ts +4 -1
- package/lib/types/utils/events.d.ts +2 -0
- package/package.json +12 -12
package/lib/cjs/index.js
CHANGED
|
@@ -33,4 +33,5 @@ tslib_1.__exportStar(require("./services/OidcInteractions"), exports);
|
|
|
33
33
|
tslib_1.__exportStar(require("./services/OidcJwks"), exports);
|
|
34
34
|
tslib_1.__exportStar(require("./services/OidcProvider"), exports);
|
|
35
35
|
tslib_1.__exportStar(require("./utils/debug"), exports);
|
|
36
|
+
tslib_1.__exportStar(require("./utils/events"), exports);
|
|
36
37
|
//# sourceMappingURL=index.js.map
|
package/lib/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,uDAA6B;AAC7B,gEAAsC;AACtC,+DAAqC;AACrC,mEAAyC;AACzC,oEAA0C;AAC1C,+DAAqC;AACrC,+DAAqC;AACrC,mEAAyC;AACzC,8DAAoC;AACpC,8DAAoC;AACpC,2DAAiC;AACjC,sEAA4C;AAC5C,uEAA6C;AAC7C,0EAAgD;AAChD,mEAAyC;AACzC,0EAAgD;AAChD,0EAAgD;AAChD,8EAAoD;AACpD,gEAAsC;AACtC,8DAAoC;AACpC,kFAAwD;AACxD,8EAAoD;AACpD,6EAAmD;AACnD,kEAAwC;AACxC,4EAAkD;AAClD,sEAA4C;AAC5C,8DAAoC;AACpC,kEAAwC;AACxC,wDAA8B","sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from \"./OidcModule\";\nexport * from \"./constants/constants\";\nexport * from \"./decorators/grantId\";\nexport * from \"./decorators/interaction\";\nexport * from \"./decorators/interactions\";\nexport * from \"./decorators/noCache\";\nexport * from \"./decorators/oidcCtx\";\nexport * from \"./decorators/oidcSession\";\nexport * from \"./decorators/params\";\nexport * from \"./decorators/prompt\";\nexport * from \"./decorators/uid\";\nexport * from \"./domain/InteractionMethods\";\nexport * from \"./domain/OidcAccountsMethods\";\nexport * from \"./domain/OidcBadInteractionName\";\nexport * from \"./domain/OidcInteraction\";\nexport * from \"./domain/OidcInteractionMethods\";\nexport * from \"./domain/OidcInteractionOptions\";\nexport * from \"./domain/OidcInteractionPromptProps\";\nexport * from \"./domain/OidcSettings\";\nexport * from \"./domain/interfaces\";\nexport * from \"./middlewares/OidcInteractionMiddleware\";\nexport * from \"./middlewares/OidcNoCacheMiddleware\";\nexport * from \"./middlewares/OidcSecureMiddleware\";\nexport * from \"./services/OidcAdapters\";\nexport * from \"./services/OidcInteractionContext\";\nexport * from \"./services/OidcInteractions\";\nexport * from \"./services/OidcJwks\";\nexport * from \"./services/OidcProvider\";\nexport * from \"./utils/debug\";\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,uDAA6B;AAC7B,gEAAsC;AACtC,+DAAqC;AACrC,mEAAyC;AACzC,oEAA0C;AAC1C,+DAAqC;AACrC,+DAAqC;AACrC,mEAAyC;AACzC,8DAAoC;AACpC,8DAAoC;AACpC,2DAAiC;AACjC,sEAA4C;AAC5C,uEAA6C;AAC7C,0EAAgD;AAChD,mEAAyC;AACzC,0EAAgD;AAChD,0EAAgD;AAChD,8EAAoD;AACpD,gEAAsC;AACtC,8DAAoC;AACpC,kFAAwD;AACxD,8EAAoD;AACpD,6EAAmD;AACnD,kEAAwC;AACxC,4EAAkD;AAClD,sEAA4C;AAC5C,8DAAoC;AACpC,kEAAwC;AACxC,wDAA8B;AAC9B,yDAA+B","sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from \"./OidcModule\";\nexport * from \"./constants/constants\";\nexport * from \"./decorators/grantId\";\nexport * from \"./decorators/interaction\";\nexport * from \"./decorators/interactions\";\nexport * from \"./decorators/noCache\";\nexport * from \"./decorators/oidcCtx\";\nexport * from \"./decorators/oidcSession\";\nexport * from \"./decorators/params\";\nexport * from \"./decorators/prompt\";\nexport * from \"./decorators/uid\";\nexport * from \"./domain/InteractionMethods\";\nexport * from \"./domain/OidcAccountsMethods\";\nexport * from \"./domain/OidcBadInteractionName\";\nexport * from \"./domain/OidcInteraction\";\nexport * from \"./domain/OidcInteractionMethods\";\nexport * from \"./domain/OidcInteractionOptions\";\nexport * from \"./domain/OidcInteractionPromptProps\";\nexport * from \"./domain/OidcSettings\";\nexport * from \"./domain/interfaces\";\nexport * from \"./middlewares/OidcInteractionMiddleware\";\nexport * from \"./middlewares/OidcNoCacheMiddleware\";\nexport * from \"./middlewares/OidcSecureMiddleware\";\nexport * from \"./services/OidcAdapters\";\nexport * from \"./services/OidcInteractionContext\";\nexport * from \"./services/OidcInteractions\";\nexport * from \"./services/OidcJwks\";\nexport * from \"./services/OidcProvider\";\nexport * from \"./utils/debug\";\nexport * from \"./utils/events\";\n"]}
|
|
@@ -7,6 +7,7 @@ const core_1 = require("@tsed/core");
|
|
|
7
7
|
const di_1 = require("@tsed/di");
|
|
8
8
|
const oidc_provider_1 = require("oidc-provider");
|
|
9
9
|
const constants_1 = require("../constants/constants");
|
|
10
|
+
const events_1 = require("../utils/events");
|
|
10
11
|
const OidcAdapters_1 = require("./OidcAdapters");
|
|
11
12
|
const OidcInteractions_1 = require("./OidcInteractions");
|
|
12
13
|
const OidcJwks_1 = require("./OidcJwks");
|
|
@@ -23,6 +24,7 @@ let OidcProvider = class OidcProvider {
|
|
|
23
24
|
adapters;
|
|
24
25
|
injector;
|
|
25
26
|
app;
|
|
27
|
+
$ctx;
|
|
26
28
|
hasConfiguration() {
|
|
27
29
|
return !!this.oidc;
|
|
28
30
|
}
|
|
@@ -95,9 +97,31 @@ let OidcProvider = class OidcProvider {
|
|
|
95
97
|
if (allowHttpLocalhost) {
|
|
96
98
|
this.allowHttpLocalhost();
|
|
97
99
|
}
|
|
100
|
+
events_1.OIDC_ERROR_EVENTS.map((event) => {
|
|
101
|
+
this.raw.on(event, this.createErrorHandler(event));
|
|
102
|
+
});
|
|
98
103
|
await this.injector.emit("$onCreateOIDC", this.raw);
|
|
99
104
|
return this.raw;
|
|
100
105
|
}
|
|
106
|
+
createErrorHandler(event) {
|
|
107
|
+
return (ctx, error, accountId, sid) => {
|
|
108
|
+
this.logger.error({
|
|
109
|
+
event: "OIDC_ERROR",
|
|
110
|
+
type: event,
|
|
111
|
+
error: {
|
|
112
|
+
error_name: error.error,
|
|
113
|
+
error_description: error.error_description,
|
|
114
|
+
error_detail: error.error_detail
|
|
115
|
+
},
|
|
116
|
+
account_id: accountId,
|
|
117
|
+
params: ctx.oidc.params,
|
|
118
|
+
headers: ctx.headers,
|
|
119
|
+
sid
|
|
120
|
+
});
|
|
121
|
+
// TODO see if we need to call platformExceptions
|
|
122
|
+
// this.platformExceptions.catch(error, ctx.request.$ctx);
|
|
123
|
+
};
|
|
124
|
+
}
|
|
101
125
|
createPrompt(instance, options) {
|
|
102
126
|
const { checks: originalChecks = [], details, ...promptOptions } = options;
|
|
103
127
|
const checks = [...(instance.checks ? instance.checks() : originalChecks)].filter(Boolean);
|
|
@@ -140,6 +164,9 @@ let OidcProvider = class OidcProvider {
|
|
|
140
164
|
}
|
|
141
165
|
return this.injector.alter("$alterOidcPolicy", policy);
|
|
142
166
|
}
|
|
167
|
+
get logger() {
|
|
168
|
+
return this.$ctx?.logger || this.injector.logger;
|
|
169
|
+
}
|
|
143
170
|
};
|
|
144
171
|
tslib_1.__decorate([
|
|
145
172
|
(0, di_1.Constant)("env"),
|
|
@@ -185,6 +212,10 @@ tslib_1.__decorate([
|
|
|
185
212
|
(0, di_1.Inject)(),
|
|
186
213
|
tslib_1.__metadata("design:type", common_1.PlatformApplication)
|
|
187
214
|
], OidcProvider.prototype, "app", void 0);
|
|
215
|
+
tslib_1.__decorate([
|
|
216
|
+
(0, common_1.InjectContext)(),
|
|
217
|
+
tslib_1.__metadata("design:type", common_1.PlatformContext)
|
|
218
|
+
], OidcProvider.prototype, "$ctx", void 0);
|
|
188
219
|
OidcProvider = tslib_1.__decorate([
|
|
189
220
|
(0, di_1.Injectable)()
|
|
190
221
|
], OidcProvider);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OidcProvider.js","sourceRoot":"","sources":["../../../src/services/OidcProvider.ts"],"names":[],"mappings":";;;;AAAA,yCAAiD;AACjD,qCAAyC;AACzC,iCAAuE;AACvE,iDAAyF;AACzF,sDAAoD;AAKpD,iDAA4C;AAC5C,yDAAoD;AACpD,yCAAoC;AAGpC,IAAa,YAAY,GAAzB,MAAa,YAAY;IACvB,GAAG,CAAe;IAGR,GAAG,CAAM;IAGT,QAAQ,CAAkB;IAG1B,SAAS,CAAkB;IAG3B,MAAM,CAAS;IAGf,IAAI,CAAe;IAGnB,YAAY,CAAS;IAGrB,QAAQ,CAAW;IAGnB,gBAAgB,CAAmB;IAGnC,QAAQ,CAAe;IAGvB,QAAQ,CAAkB;IAG1B,GAAG,CAAsB;IAEnC,gBAAgB;QACd,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;IACrB,CAAC;IAED,KAAK,CAAC,gBAAgB;QACpB,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,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AGnB;IADC,IAAA,aAAQ,EAAC,UAAU,CAAC;;8CACe;AAGpC;IADC,IAAA,aAAQ,EAAC,WAAW,CAAC;;+CACe;AAGrC;IADC,IAAA,aAAQ,EAAC,aAAa,EAAE,EAAE,CAAC;;4CACH;AAGzB;IADC,IAAA,aAAQ,EAAC,MAAM,CAAC;;0CACY;AAG7B;IADC,IAAA,aAAQ,EAAC,eAAe,CAAC;;kDACK;AAG/B;IADC,IAAA,WAAM,GAAE;sCACW,mBAAQ;8CAAC;AAG7B;IADC,IAAA,WAAM,GAAE;sCACmB,mCAAgB;sDAAC;AAG7C;IADC,IAAA,WAAM,GAAE;sCACW,2BAAY;8CAAC;AAGjC;IADC,IAAA,WAAM,GAAE;sCACW,oBAAe;8CAAC;AAGpC;IADC,IAAA,WAAM,GAAE;sCACM,4BAAmB;yCAAC;AAlCxB,YAAY;IADxB,IAAA,eAAU,GAAE;GACA,YAAY,CAoMxB;AApMY,oCAAY","sourcesContent":["import {PlatformApplication} from \"@tsed/common\";\nimport {Env, setValue} from \"@tsed/core\";\nimport {Constant, Inject, Injectable, InjectorService} from \"@tsed/di\";\nimport {Configuration, interactionPolicy, Provider as OIDCProvider} from \"oidc-provider\";\nimport {INTERACTIONS} from \"../constants/constants\";\nimport {InteractionMethods} from \"../domain/InteractionMethods\";\nimport {OidcAccountsMethods} from \"../domain/OidcAccountsMethods\";\nimport {OidcInteractionOptions} from \"../domain/OidcInteractionOptions\";\nimport {OidcSettings} from \"../domain/OidcSettings\";\nimport {OidcAdapters} from \"./OidcAdapters\";\nimport {OidcInteractions} from \"./OidcInteractions\";\nimport {OidcJwks} from \"./OidcJwks\";\n\n@Injectable()\nexport class OidcProvider {\n raw: OIDCProvider;\n\n @Constant(\"env\")\n protected env: Env;\n\n @Constant(\"httpPort\")\n protected httpPort: number | string;\n\n @Constant(\"httpsPort\")\n protected httpsPort: number | string;\n\n @Constant(\"oidc.issuer\", \"\")\n protected issuer: string;\n\n @Constant(\"oidc\")\n protected oidc: OidcSettings;\n\n @Constant(\"PLATFORM_NAME\")\n protected platformName: string;\n\n @Inject()\n protected oidcJwks: OidcJwks;\n\n @Inject()\n protected oidcInteractions: OidcInteractions;\n\n @Inject()\n protected adapters: OidcAdapters;\n\n @Inject()\n protected injector: InjectorService;\n\n @Inject()\n protected app: PlatformApplication;\n\n hasConfiguration() {\n return !!this.oidc;\n }\n\n async getConfiguration(): Promise<Configuration> {\n const [jwks, adapter] = await Promise.all([this.oidcJwks.getJwks(), this.adapters.createAdapterClass()]);\n const {\n issuer,\n jwksPath,\n secureKey,\n proxy,\n Accounts,\n secureCookies = this.env == Env.PROD,\n Adapter,\n connectionName,\n ...options\n } = this.oidc;\n\n const configuration: Configuration = {\n interactions: {\n /* istanbul ignore next */\n url: (ctx, interaction) => `interaction/${interaction.uid}`\n },\n ...options,\n adapter,\n jwks\n };\n\n if (Accounts) {\n configuration.findAccount = (ctx, id, token) => this.injector.get<OidcAccountsMethods>(Accounts)!.findAccount(id, token);\n }\n\n if (secureCookies) {\n setValue(configuration, \"cookies.short.secure\", true);\n setValue(configuration, \"cookies.long.secure\", true);\n }\n\n const policy = this.getPolicy();\n if (policy) {\n setValue(configuration, \"interactions.policy\", policy);\n }\n\n const url = this.getInteractionsUrl();\n if (url) {\n setValue(configuration, \"interactions.url\", url);\n }\n\n return configuration;\n }\n\n getIssuer() {\n if (this.issuer) {\n return this.issuer;\n }\n\n // istanbul ignore next\n if (this.httpsPort) {\n return `https://localhost:${this.httpsPort}`;\n }\n\n return `http://localhost:${this.httpPort}`;\n }\n\n get(): OIDCProvider {\n return this.raw;\n }\n\n /**\n * Create a new instance of OidcProvider\n */\n async create(): Promise<void | OIDCProvider> {\n const {proxy = this.env === Env.PROD, secureKey, allowHttpLocalhost = this.env !== Env.PROD} = this.oidc;\n const configuration = await this.getConfiguration();\n\n await this.injector.alterAsync(\"$alterOidcConfiguration\", configuration);\n\n const oidcProvider = new OIDCProvider(this.getIssuer(), configuration);\n\n if (proxy) {\n // istanbul ignore next\n switch (this.platformName) {\n default:\n case \"express\":\n oidcProvider.proxy = true;\n break;\n case \"koa\":\n (this.app.rawApp as any).proxy = true;\n break;\n }\n }\n\n if (secureKey) {\n oidcProvider.app.keys = secureKey;\n }\n\n this.raw = oidcProvider;\n\n if (allowHttpLocalhost) {\n this.allowHttpLocalhost();\n }\n\n await this.injector.emit(\"$onCreateOIDC\", this.raw);\n\n return this.raw;\n }\n\n public createPrompt(instance: InteractionMethods, options: OidcInteractionOptions) {\n const {checks: originalChecks = [], details, ...promptOptions} = options;\n const checks = [...(instance.checks ? instance.checks() : originalChecks)].filter(Boolean);\n\n return new interactionPolicy.Prompt(promptOptions, instance.details ? instance.details.bind(instance) : details, ...checks);\n }\n\n private getInteractionsUrl() {\n const provider = this.injector.getProviders().find((provider) => provider.subType === INTERACTIONS);\n\n if (provider) {\n return (ctx: any, interaction: any) => {\n // eslint-disable-line no-unused-vars\n return provider.path.replace(/:uid/, interaction.uid);\n };\n }\n }\n\n private allowHttpLocalhost() {\n const {invalidate: orig} = (this.raw.Client as any).Schema.prototype;\n\n (this.raw.Client as any).Schema.prototype.invalidate = function invalidate(message: string, code: string) {\n if (code === \"implicit-force-https\" || code === \"implicit-forbid-localhost\") {\n return;\n }\n\n /* istanbul ignore next */\n return orig.call(this, message);\n };\n }\n\n private getPolicy() {\n const policy = interactionPolicy.base();\n const interactions = this.oidcInteractions.getInteractions();\n\n if (interactions.length) {\n interactions.forEach((provider) => {\n const instance = this.injector.get<InteractionMethods>(provider.token)!;\n const options = provider.store.get(\"interactionOptions\");\n\n if (!policy.get(options.name)) {\n const prompt = this.createPrompt(instance, options);\n\n policy.add(prompt, options.priority);\n }\n\n if (instance.$onCreate) {\n instance.$onCreate(policy.get(options.name)!);\n }\n });\n }\n\n return this.injector.alter(\"$alterOidcPolicy\", policy);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"OidcProvider.js","sourceRoot":"","sources":["../../../src/services/OidcProvider.ts"],"names":[],"mappings":";;;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AC,KAAK,CAAC,kBAAkB,EAAE,MAAM,CAAC,CAAC;IACzD,CAAC;IAED,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,IAAI,EAAE,MAAM,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;IACnD,CAAC;CACF,CAAA;AAhOC;IADC,IAAA,aAAQ,EAAC,KAAK,CAAC;;yCACG;AAGnB;IADC,IAAA,aAAQ,EAAC,UAAU,CAAC;;8CACe;AAGpC;IADC,IAAA,aAAQ,EAAC,WAAW,CAAC;;+CACe;AAGrC;IADC,IAAA,aAAQ,EAAC,aAAa,EAAE,EAAE,CAAC;;4CACH;AAGzB;IADC,IAAA,aAAQ,EAAC,MAAM,CAAC;;0CACY;AAG7B;IADC,IAAA,aAAQ,EAAC,eAAe,CAAC;;kDACK;AAG/B;IADC,IAAA,WAAM,GAAE;sCACW,mBAAQ;8CAAC;AAG7B;IADC,IAAA,WAAM,GAAE;sCACmB,mCAAgB;sDAAC;AAG7C;IADC,IAAA,WAAM,GAAE;sCACW,2BAAY;8CAAC;AAGjC;IADC,IAAA,WAAM,GAAE;sCACW,oBAAe;8CAAC;AAGpC;IADC,IAAA,WAAM,GAAE;sCACM,4BAAmB;yCAAC;AAGnC;IADC,IAAA,sBAAa,GAAE;sCACC,wBAAe;0CAAC;AArCtB,YAAY;IADxB,IAAA,eAAU,GAAE;GACA,YAAY,CAoOxB;AApOY,oCAAY","sourcesContent":["import {InjectContext, PlatformApplication, PlatformContext} from \"@tsed/common\";\nimport {Env, setValue} from \"@tsed/core\";\nimport {Constant, Inject, Injectable, InjectorService} from \"@tsed/di\";\nimport {Configuration, interactionPolicy, KoaContextWithOIDC, Provider as OIDCProvider} from \"oidc-provider\";\nimport {INTERACTIONS} from \"../constants/constants\";\nimport {InteractionMethods} from \"../domain/InteractionMethods\";\nimport {OidcAccountsMethods} from \"../domain/OidcAccountsMethods\";\nimport {OidcInteractionOptions} from \"../domain/OidcInteractionOptions\";\nimport {OidcSettings} from \"../domain/OidcSettings\";\nimport {OIDC_ERROR_EVENTS} from \"../utils/events\";\nimport {OidcAdapters} from \"./OidcAdapters\";\nimport {OidcInteractions} from \"./OidcInteractions\";\nimport {OidcJwks} from \"./OidcJwks\";\n\n@Injectable()\nexport class OidcProvider {\n raw: OIDCProvider;\n\n @Constant(\"env\")\n protected env: Env;\n\n @Constant(\"httpPort\")\n protected httpPort: number | string;\n\n @Constant(\"httpsPort\")\n protected httpsPort: number | string;\n\n @Constant(\"oidc.issuer\", \"\")\n protected issuer: string;\n\n @Constant(\"oidc\")\n protected oidc: OidcSettings;\n\n @Constant(\"PLATFORM_NAME\")\n protected platformName: string;\n\n @Inject()\n protected oidcJwks: OidcJwks;\n\n @Inject()\n protected oidcInteractions: OidcInteractions;\n\n @Inject()\n protected adapters: OidcAdapters;\n\n @Inject()\n protected injector: InjectorService;\n\n @Inject()\n protected app: PlatformApplication;\n\n @InjectContext()\n protected $ctx?: PlatformContext;\n\n hasConfiguration() {\n return !!this.oidc;\n }\n\n async getConfiguration(): Promise<Configuration> {\n const [jwks, adapter] = await Promise.all([this.oidcJwks.getJwks(), this.adapters.createAdapterClass()]);\n const {\n issuer,\n jwksPath,\n secureKey,\n proxy,\n Accounts,\n secureCookies = this.env == Env.PROD,\n Adapter,\n connectionName,\n ...options\n } = this.oidc;\n\n const configuration: Configuration = {\n interactions: {\n /* istanbul ignore next */\n url: (ctx, interaction) => `interaction/${interaction.uid}`\n },\n ...options,\n adapter,\n jwks\n };\n\n if (Accounts) {\n configuration.findAccount = (ctx, id, token) => this.injector.get<OidcAccountsMethods>(Accounts)!.findAccount(id, token);\n }\n\n if (secureCookies) {\n setValue(configuration, \"cookies.short.secure\", true);\n setValue(configuration, \"cookies.long.secure\", true);\n }\n\n const policy = this.getPolicy();\n if (policy) {\n setValue(configuration, \"interactions.policy\", policy);\n }\n\n const url = this.getInteractionsUrl();\n if (url) {\n setValue(configuration, \"interactions.url\", url);\n }\n\n return configuration;\n }\n\n getIssuer() {\n if (this.issuer) {\n return this.issuer;\n }\n\n // istanbul ignore next\n if (this.httpsPort) {\n return `https://localhost:${this.httpsPort}`;\n }\n\n return `http://localhost:${this.httpPort}`;\n }\n\n get(): OIDCProvider {\n return this.raw;\n }\n\n /**\n * Create a new instance of OidcProvider\n */\n async create(): Promise<void | OIDCProvider> {\n const {proxy = this.env === Env.PROD, secureKey, allowHttpLocalhost = this.env !== Env.PROD} = this.oidc;\n const configuration = await this.getConfiguration();\n\n await this.injector.alterAsync(\"$alterOidcConfiguration\", configuration);\n\n const oidcProvider = new OIDCProvider(this.getIssuer(), configuration);\n\n if (proxy) {\n // istanbul ignore next\n switch (this.platformName) {\n default:\n case \"express\":\n oidcProvider.proxy = true;\n break;\n case \"koa\":\n (this.app.rawApp as any).proxy = true;\n break;\n }\n }\n\n if (secureKey) {\n oidcProvider.app.keys = secureKey;\n }\n\n this.raw = oidcProvider;\n\n if (allowHttpLocalhost) {\n this.allowHttpLocalhost();\n }\n\n OIDC_ERROR_EVENTS.map((event) => {\n this.raw.on(event, this.createErrorHandler(event));\n });\n\n await this.injector.emit(\"$onCreateOIDC\", this.raw);\n\n return this.raw;\n }\n\n private createErrorHandler(event: string) {\n return (ctx: KoaContextWithOIDC, error: any, accountId?: string, sid?: string) => {\n this.logger.error({\n event: \"OIDC_ERROR\",\n type: event,\n error: {\n error_name: error.error,\n error_description: error.error_description,\n error_detail: error.error_detail\n },\n account_id: accountId,\n params: ctx.oidc.params,\n headers: ctx.headers,\n sid\n });\n\n // TODO see if we need to call platformExceptions\n // this.platformExceptions.catch(error, ctx.request.$ctx);\n };\n }\n\n public createPrompt(instance: InteractionMethods, options: OidcInteractionOptions) {\n const {checks: originalChecks = [], details, ...promptOptions} = options;\n const checks = [...(instance.checks ? instance.checks() : originalChecks)].filter(Boolean);\n\n return new interactionPolicy.Prompt(promptOptions, instance.details ? instance.details.bind(instance) : details, ...checks);\n }\n\n private getInteractionsUrl() {\n const provider = this.injector.getProviders().find((provider) => provider.subType === INTERACTIONS);\n\n if (provider) {\n return (ctx: any, interaction: any) => {\n // eslint-disable-line no-unused-vars\n return provider.path.replace(/:uid/, interaction.uid);\n };\n }\n }\n\n private allowHttpLocalhost() {\n const {invalidate: orig} = (this.raw.Client as any).Schema.prototype;\n\n (this.raw.Client as any).Schema.prototype.invalidate = function invalidate(message: string, code: string) {\n if (code === \"implicit-force-https\" || code === \"implicit-forbid-localhost\") {\n return;\n }\n\n /* istanbul ignore next */\n return orig.call(this, message);\n };\n }\n\n private getPolicy() {\n const policy = interactionPolicy.base();\n const interactions = this.oidcInteractions.getInteractions();\n\n if (interactions.length) {\n interactions.forEach((provider) => {\n const instance = this.injector.get<InteractionMethods>(provider.token)!;\n const options = provider.store.get(\"interactionOptions\");\n\n if (!policy.get(options.name)) {\n const prompt = this.createPrompt(instance, options);\n\n policy.add(prompt, options.priority);\n }\n\n if (instance.$onCreate) {\n instance.$onCreate(policy.get(options.name)!);\n }\n });\n }\n\n return this.injector.alter(\"$alterOidcPolicy\", policy);\n }\n\n get logger() {\n return this.$ctx?.logger || this.injector.logger;\n }\n}\n"]}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OIDC_ERROR_EVENTS = exports.OIDC_EVENTS = void 0;
|
|
4
|
+
exports.OIDC_EVENTS = [
|
|
5
|
+
"access_token.destroyed",
|
|
6
|
+
"access_token.saved",
|
|
7
|
+
"access_token.issued",
|
|
8
|
+
"authorization_code.consumed",
|
|
9
|
+
"authorization_code.destroyed",
|
|
10
|
+
"authorization_code.saved",
|
|
11
|
+
"authorization.accepted",
|
|
12
|
+
"authorization.error",
|
|
13
|
+
"authorization.success",
|
|
14
|
+
"backchannel.error",
|
|
15
|
+
"backchannel.success",
|
|
16
|
+
"jwks.error",
|
|
17
|
+
"client_credentials.destroyed",
|
|
18
|
+
"client_credentials.saved",
|
|
19
|
+
"client_credentials.issued",
|
|
20
|
+
"device_code.consumed",
|
|
21
|
+
"device_code.destroyed",
|
|
22
|
+
"device_code.saved",
|
|
23
|
+
"discovery.error",
|
|
24
|
+
"end_session.error",
|
|
25
|
+
"end_session.success",
|
|
26
|
+
"grant.error",
|
|
27
|
+
"grant.revoked",
|
|
28
|
+
"grant.success",
|
|
29
|
+
"initial_access_token.destroyed",
|
|
30
|
+
"initial_access_token.saved",
|
|
31
|
+
"interaction.destroyed",
|
|
32
|
+
"interaction.ended",
|
|
33
|
+
"interaction.saved",
|
|
34
|
+
"interaction.started",
|
|
35
|
+
"introspection.error",
|
|
36
|
+
"replay_detection.destroyed",
|
|
37
|
+
"replay_detection.saved",
|
|
38
|
+
"pushed_authorization_request.error",
|
|
39
|
+
"pushed_authorization_request.success",
|
|
40
|
+
"pushed_authorization_request.destroyed",
|
|
41
|
+
"pushed_authorization_request.saved",
|
|
42
|
+
"refresh_token.consumed",
|
|
43
|
+
"refresh_token.destroyed",
|
|
44
|
+
"refresh_token.saved",
|
|
45
|
+
"registration_access_token.destroyed",
|
|
46
|
+
"registration_access_token.saved",
|
|
47
|
+
"registration_create.error",
|
|
48
|
+
"registration_create.success",
|
|
49
|
+
"registration_delete.error",
|
|
50
|
+
"registration_delete.success",
|
|
51
|
+
"registration_read.error",
|
|
52
|
+
"registration_update.error",
|
|
53
|
+
"registration_update.success",
|
|
54
|
+
"revocation.error",
|
|
55
|
+
"server_error",
|
|
56
|
+
"session.destroyed",
|
|
57
|
+
"session.saved",
|
|
58
|
+
"userinfo.error"
|
|
59
|
+
];
|
|
60
|
+
exports.OIDC_ERROR_EVENTS = exports.OIDC_EVENTS.filter((e) => e.includes("error"));
|
|
61
|
+
//# sourceMappingURL=events.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.js","sourceRoot":"","sources":["../../../src/utils/events.ts"],"names":[],"mappings":";;;AAAa,QAAA,WAAW,GAAG;IACzB,wBAAwB;IACxB,oBAAoB;IACpB,qBAAqB;IACrB,6BAA6B;IAC7B,8BAA8B;IAC9B,0BAA0B;IAC1B,wBAAwB;IACxB,qBAAqB;IACrB,uBAAuB;IACvB,mBAAmB;IACnB,qBAAqB;IACrB,YAAY;IACZ,8BAA8B;IAC9B,0BAA0B;IAC1B,2BAA2B;IAC3B,sBAAsB;IACtB,uBAAuB;IACvB,mBAAmB;IACnB,iBAAiB;IACjB,mBAAmB;IACnB,qBAAqB;IACrB,aAAa;IACb,eAAe;IACf,eAAe;IACf,gCAAgC;IAChC,4BAA4B;IAC5B,uBAAuB;IACvB,mBAAmB;IACnB,mBAAmB;IACnB,qBAAqB;IACrB,qBAAqB;IACrB,4BAA4B;IAC5B,wBAAwB;IACxB,oCAAoC;IACpC,sCAAsC;IACtC,wCAAwC;IACxC,oCAAoC;IACpC,wBAAwB;IACxB,yBAAyB;IACzB,qBAAqB;IACrB,qCAAqC;IACrC,iCAAiC;IACjC,2BAA2B;IAC3B,6BAA6B;IAC7B,2BAA2B;IAC3B,6BAA6B;IAC7B,yBAAyB;IACzB,2BAA2B;IAC3B,6BAA6B;IAC7B,kBAAkB;IAClB,cAAc;IACd,mBAAmB;IACnB,eAAe;IACf,gBAAgB;CACjB,CAAC;AAEW,QAAA,iBAAiB,GAAG,mBAAW,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC","sourcesContent":["export const OIDC_EVENTS = [\n \"access_token.destroyed\",\n \"access_token.saved\",\n \"access_token.issued\",\n \"authorization_code.consumed\",\n \"authorization_code.destroyed\",\n \"authorization_code.saved\",\n \"authorization.accepted\",\n \"authorization.error\",\n \"authorization.success\",\n \"backchannel.error\",\n \"backchannel.success\",\n \"jwks.error\",\n \"client_credentials.destroyed\",\n \"client_credentials.saved\",\n \"client_credentials.issued\",\n \"device_code.consumed\",\n \"device_code.destroyed\",\n \"device_code.saved\",\n \"discovery.error\",\n \"end_session.error\",\n \"end_session.success\",\n \"grant.error\",\n \"grant.revoked\",\n \"grant.success\",\n \"initial_access_token.destroyed\",\n \"initial_access_token.saved\",\n \"interaction.destroyed\",\n \"interaction.ended\",\n \"interaction.saved\",\n \"interaction.started\",\n \"introspection.error\",\n \"replay_detection.destroyed\",\n \"replay_detection.saved\",\n \"pushed_authorization_request.error\",\n \"pushed_authorization_request.success\",\n \"pushed_authorization_request.destroyed\",\n \"pushed_authorization_request.saved\",\n \"refresh_token.consumed\",\n \"refresh_token.destroyed\",\n \"refresh_token.saved\",\n \"registration_access_token.destroyed\",\n \"registration_access_token.saved\",\n \"registration_create.error\",\n \"registration_create.success\",\n \"registration_delete.error\",\n \"registration_delete.success\",\n \"registration_read.error\",\n \"registration_update.error\",\n \"registration_update.success\",\n \"revocation.error\",\n \"server_error\",\n \"session.destroyed\",\n \"session.saved\",\n \"userinfo.error\"\n];\n\nexport const OIDC_ERROR_EVENTS = OIDC_EVENTS.filter((e) => e.includes(\"error\"));\n"]}
|
package/lib/esm/index.js
CHANGED
package/lib/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,cAAc,CAAC;AAC7B,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,0BAA0B,CAAC;AACzC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,0BAA0B,CAAC;AACzC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,iCAAiC,CAAC;AAChD,cAAc,0BAA0B,CAAC;AACzC,cAAc,iCAAiC,CAAC;AAChD,cAAc,iCAAiC,CAAC;AAChD,cAAc,qCAAqC,CAAC;AACpD,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,yCAAyC,CAAC;AACxD,cAAc,qCAAqC,CAAC;AACpD,cAAc,oCAAoC,CAAC;AACnD,cAAc,yBAAyB,CAAC;AACxC,cAAc,mCAAmC,CAAC;AAClD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,qBAAqB,CAAC;AACpC,cAAc,yBAAyB,CAAC;AACxC,cAAc,eAAe,CAAC","sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from \"./OidcModule\";\nexport * from \"./constants/constants\";\nexport * from \"./decorators/grantId\";\nexport * from \"./decorators/interaction\";\nexport * from \"./decorators/interactions\";\nexport * from \"./decorators/noCache\";\nexport * from \"./decorators/oidcCtx\";\nexport * from \"./decorators/oidcSession\";\nexport * from \"./decorators/params\";\nexport * from \"./decorators/prompt\";\nexport * from \"./decorators/uid\";\nexport * from \"./domain/InteractionMethods\";\nexport * from \"./domain/OidcAccountsMethods\";\nexport * from \"./domain/OidcBadInteractionName\";\nexport * from \"./domain/OidcInteraction\";\nexport * from \"./domain/OidcInteractionMethods\";\nexport * from \"./domain/OidcInteractionOptions\";\nexport * from \"./domain/OidcInteractionPromptProps\";\nexport * from \"./domain/OidcSettings\";\nexport * from \"./domain/interfaces\";\nexport * from \"./middlewares/OidcInteractionMiddleware\";\nexport * from \"./middlewares/OidcNoCacheMiddleware\";\nexport * from \"./middlewares/OidcSecureMiddleware\";\nexport * from \"./services/OidcAdapters\";\nexport * from \"./services/OidcInteractionContext\";\nexport * from \"./services/OidcInteractions\";\nexport * from \"./services/OidcJwks\";\nexport * from \"./services/OidcProvider\";\nexport * from \"./utils/debug\";\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,cAAc,CAAC;AAC7B,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,0BAA0B,CAAC;AACzC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,0BAA0B,CAAC;AACzC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,iCAAiC,CAAC;AAChD,cAAc,0BAA0B,CAAC;AACzC,cAAc,iCAAiC,CAAC;AAChD,cAAc,iCAAiC,CAAC;AAChD,cAAc,qCAAqC,CAAC;AACpD,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,yCAAyC,CAAC;AACxD,cAAc,qCAAqC,CAAC;AACpD,cAAc,oCAAoC,CAAC;AACnD,cAAc,yBAAyB,CAAC;AACxC,cAAc,mCAAmC,CAAC;AAClD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,qBAAqB,CAAC;AACpC,cAAc,yBAAyB,CAAC;AACxC,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC","sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from \"./OidcModule\";\nexport * from \"./constants/constants\";\nexport * from \"./decorators/grantId\";\nexport * from \"./decorators/interaction\";\nexport * from \"./decorators/interactions\";\nexport * from \"./decorators/noCache\";\nexport * from \"./decorators/oidcCtx\";\nexport * from \"./decorators/oidcSession\";\nexport * from \"./decorators/params\";\nexport * from \"./decorators/prompt\";\nexport * from \"./decorators/uid\";\nexport * from \"./domain/InteractionMethods\";\nexport * from \"./domain/OidcAccountsMethods\";\nexport * from \"./domain/OidcBadInteractionName\";\nexport * from \"./domain/OidcInteraction\";\nexport * from \"./domain/OidcInteractionMethods\";\nexport * from \"./domain/OidcInteractionOptions\";\nexport * from \"./domain/OidcInteractionPromptProps\";\nexport * from \"./domain/OidcSettings\";\nexport * from \"./domain/interfaces\";\nexport * from \"./middlewares/OidcInteractionMiddleware\";\nexport * from \"./middlewares/OidcNoCacheMiddleware\";\nexport * from \"./middlewares/OidcSecureMiddleware\";\nexport * from \"./services/OidcAdapters\";\nexport * from \"./services/OidcInteractionContext\";\nexport * from \"./services/OidcInteractions\";\nexport * from \"./services/OidcJwks\";\nexport * from \"./services/OidcProvider\";\nexport * from \"./utils/debug\";\nexport * from \"./utils/events\";\n"]}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { __decorate, __metadata } from "tslib";
|
|
2
|
-
import { PlatformApplication } from "@tsed/common";
|
|
2
|
+
import { InjectContext, PlatformApplication, PlatformContext } from "@tsed/common";
|
|
3
3
|
import { Env, setValue } from "@tsed/core";
|
|
4
4
|
import { Constant, Inject, Injectable, InjectorService } from "@tsed/di";
|
|
5
5
|
import { interactionPolicy, Provider as OIDCProvider } from "oidc-provider";
|
|
6
6
|
import { INTERACTIONS } from "../constants/constants.js";
|
|
7
|
+
import { OIDC_ERROR_EVENTS } from "../utils/events.js";
|
|
7
8
|
import { OidcAdapters } from "./OidcAdapters.js";
|
|
8
9
|
import { OidcInteractions } from "./OidcInteractions.js";
|
|
9
10
|
import { OidcJwks } from "./OidcJwks.js";
|
|
@@ -20,6 +21,7 @@ let OidcProvider = class OidcProvider {
|
|
|
20
21
|
adapters;
|
|
21
22
|
injector;
|
|
22
23
|
app;
|
|
24
|
+
$ctx;
|
|
23
25
|
hasConfiguration() {
|
|
24
26
|
return !!this.oidc;
|
|
25
27
|
}
|
|
@@ -92,9 +94,31 @@ let OidcProvider = class OidcProvider {
|
|
|
92
94
|
if (allowHttpLocalhost) {
|
|
93
95
|
this.allowHttpLocalhost();
|
|
94
96
|
}
|
|
97
|
+
OIDC_ERROR_EVENTS.map((event) => {
|
|
98
|
+
this.raw.on(event, this.createErrorHandler(event));
|
|
99
|
+
});
|
|
95
100
|
await this.injector.emit("$onCreateOIDC", this.raw);
|
|
96
101
|
return this.raw;
|
|
97
102
|
}
|
|
103
|
+
createErrorHandler(event) {
|
|
104
|
+
return (ctx, error, accountId, sid) => {
|
|
105
|
+
this.logger.error({
|
|
106
|
+
event: "OIDC_ERROR",
|
|
107
|
+
type: event,
|
|
108
|
+
error: {
|
|
109
|
+
error_name: error.error,
|
|
110
|
+
error_description: error.error_description,
|
|
111
|
+
error_detail: error.error_detail
|
|
112
|
+
},
|
|
113
|
+
account_id: accountId,
|
|
114
|
+
params: ctx.oidc.params,
|
|
115
|
+
headers: ctx.headers,
|
|
116
|
+
sid
|
|
117
|
+
});
|
|
118
|
+
// TODO see if we need to call platformExceptions
|
|
119
|
+
// this.platformExceptions.catch(error, ctx.request.$ctx);
|
|
120
|
+
};
|
|
121
|
+
}
|
|
98
122
|
createPrompt(instance, options) {
|
|
99
123
|
const { checks: originalChecks = [], details, ...promptOptions } = options;
|
|
100
124
|
const checks = [...(instance.checks ? instance.checks() : originalChecks)].filter(Boolean);
|
|
@@ -137,6 +161,9 @@ let OidcProvider = class OidcProvider {
|
|
|
137
161
|
}
|
|
138
162
|
return this.injector.alter("$alterOidcPolicy", policy);
|
|
139
163
|
}
|
|
164
|
+
get logger() {
|
|
165
|
+
return this.$ctx?.logger || this.injector.logger;
|
|
166
|
+
}
|
|
140
167
|
};
|
|
141
168
|
__decorate([
|
|
142
169
|
Constant("env"),
|
|
@@ -182,6 +209,10 @@ __decorate([
|
|
|
182
209
|
Inject(),
|
|
183
210
|
__metadata("design:type", PlatformApplication)
|
|
184
211
|
], OidcProvider.prototype, "app", void 0);
|
|
212
|
+
__decorate([
|
|
213
|
+
InjectContext(),
|
|
214
|
+
__metadata("design:type", PlatformContext)
|
|
215
|
+
], OidcProvider.prototype, "$ctx", void 0);
|
|
185
216
|
OidcProvider = __decorate([
|
|
186
217
|
Injectable()
|
|
187
218
|
], OidcProvider);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OidcProvider.js","sourceRoot":"","sources":["../../../src/services/OidcProvider.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,mBAAmB,EAAC,M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AAE;8BACW,YAAY;8CAAC;AAGjC;IADC,MAAM,EAAE;8BACW,eAAe;8CAAC;AAGpC;IADC,MAAM,EAAE;8BACM,mBAAmB;yCAAC;AAlCxB,YAAY;IADxB,UAAU,EAAE;GACA,YAAY,CAoMxB;SApMY,YAAY","sourcesContent":["import {PlatformApplication} from \"@tsed/common\";\nimport {Env, setValue} from \"@tsed/core\";\nimport {Constant, Inject, Injectable, InjectorService} from \"@tsed/di\";\nimport {Configuration, interactionPolicy, Provider as OIDCProvider} from \"oidc-provider\";\nimport {INTERACTIONS} from \"../constants/constants\";\nimport {InteractionMethods} from \"../domain/InteractionMethods\";\nimport {OidcAccountsMethods} from \"../domain/OidcAccountsMethods\";\nimport {OidcInteractionOptions} from \"../domain/OidcInteractionOptions\";\nimport {OidcSettings} from \"../domain/OidcSettings\";\nimport {OidcAdapters} from \"./OidcAdapters\";\nimport {OidcInteractions} from \"./OidcInteractions\";\nimport {OidcJwks} from \"./OidcJwks\";\n\n@Injectable()\nexport class OidcProvider {\n raw: OIDCProvider;\n\n @Constant(\"env\")\n protected env: Env;\n\n @Constant(\"httpPort\")\n protected httpPort: number | string;\n\n @Constant(\"httpsPort\")\n protected httpsPort: number | string;\n\n @Constant(\"oidc.issuer\", \"\")\n protected issuer: string;\n\n @Constant(\"oidc\")\n protected oidc: OidcSettings;\n\n @Constant(\"PLATFORM_NAME\")\n protected platformName: string;\n\n @Inject()\n protected oidcJwks: OidcJwks;\n\n @Inject()\n protected oidcInteractions: OidcInteractions;\n\n @Inject()\n protected adapters: OidcAdapters;\n\n @Inject()\n protected injector: InjectorService;\n\n @Inject()\n protected app: PlatformApplication;\n\n hasConfiguration() {\n return !!this.oidc;\n }\n\n async getConfiguration(): Promise<Configuration> {\n const [jwks, adapter] = await Promise.all([this.oidcJwks.getJwks(), this.adapters.createAdapterClass()]);\n const {\n issuer,\n jwksPath,\n secureKey,\n proxy,\n Accounts,\n secureCookies = this.env == Env.PROD,\n Adapter,\n connectionName,\n ...options\n } = this.oidc;\n\n const configuration: Configuration = {\n interactions: {\n /* istanbul ignore next */\n url: (ctx, interaction) => `interaction/${interaction.uid}`\n },\n ...options,\n adapter,\n jwks\n };\n\n if (Accounts) {\n configuration.findAccount = (ctx, id, token) => this.injector.get<OidcAccountsMethods>(Accounts)!.findAccount(id, token);\n }\n\n if (secureCookies) {\n setValue(configuration, \"cookies.short.secure\", true);\n setValue(configuration, \"cookies.long.secure\", true);\n }\n\n const policy = this.getPolicy();\n if (policy) {\n setValue(configuration, \"interactions.policy\", policy);\n }\n\n const url = this.getInteractionsUrl();\n if (url) {\n setValue(configuration, \"interactions.url\", url);\n }\n\n return configuration;\n }\n\n getIssuer() {\n if (this.issuer) {\n return this.issuer;\n }\n\n // istanbul ignore next\n if (this.httpsPort) {\n return `https://localhost:${this.httpsPort}`;\n }\n\n return `http://localhost:${this.httpPort}`;\n }\n\n get(): OIDCProvider {\n return this.raw;\n }\n\n /**\n * Create a new instance of OidcProvider\n */\n async create(): Promise<void | OIDCProvider> {\n const {proxy = this.env === Env.PROD, secureKey, allowHttpLocalhost = this.env !== Env.PROD} = this.oidc;\n const configuration = await this.getConfiguration();\n\n await this.injector.alterAsync(\"$alterOidcConfiguration\", configuration);\n\n const oidcProvider = new OIDCProvider(this.getIssuer(), configuration);\n\n if (proxy) {\n // istanbul ignore next\n switch (this.platformName) {\n default:\n case \"express\":\n oidcProvider.proxy = true;\n break;\n case \"koa\":\n (this.app.rawApp as any).proxy = true;\n break;\n }\n }\n\n if (secureKey) {\n oidcProvider.app.keys = secureKey;\n }\n\n this.raw = oidcProvider;\n\n if (allowHttpLocalhost) {\n this.allowHttpLocalhost();\n }\n\n await this.injector.emit(\"$onCreateOIDC\", this.raw);\n\n return this.raw;\n }\n\n public createPrompt(instance: InteractionMethods, options: OidcInteractionOptions) {\n const {checks: originalChecks = [], details, ...promptOptions} = options;\n const checks = [...(instance.checks ? instance.checks() : originalChecks)].filter(Boolean);\n\n return new interactionPolicy.Prompt(promptOptions, instance.details ? instance.details.bind(instance) : details, ...checks);\n }\n\n private getInteractionsUrl() {\n const provider = this.injector.getProviders().find((provider) => provider.subType === INTERACTIONS);\n\n if (provider) {\n return (ctx: any, interaction: any) => {\n // eslint-disable-line no-unused-vars\n return provider.path.replace(/:uid/, interaction.uid);\n };\n }\n }\n\n private allowHttpLocalhost() {\n const {invalidate: orig} = (this.raw.Client as any).Schema.prototype;\n\n (this.raw.Client as any).Schema.prototype.invalidate = function invalidate(message: string, code: string) {\n if (code === \"implicit-force-https\" || code === \"implicit-forbid-localhost\") {\n return;\n }\n\n /* istanbul ignore next */\n return orig.call(this, message);\n };\n }\n\n private getPolicy() {\n const policy = interactionPolicy.base();\n const interactions = this.oidcInteractions.getInteractions();\n\n if (interactions.length) {\n interactions.forEach((provider) => {\n const instance = this.injector.get<InteractionMethods>(provider.token)!;\n const options = provider.store.get(\"interactionOptions\");\n\n if (!policy.get(options.name)) {\n const prompt = this.createPrompt(instance, options);\n\n policy.add(prompt, options.priority);\n }\n\n if (instance.$onCreate) {\n instance.$onCreate(policy.get(options.name)!);\n }\n });\n }\n\n return this.injector.alter(\"$alterOidcPolicy\", policy);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"OidcProvider.js","sourceRoot":"","sources":["../../../src/services/OidcProvider.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,aAAa,EAAE,mBAAmB,EAAE,eAAe,EAAC,MAAM,cAAc,CAAC;AACjF,OAAO,EAAC,GAAG,EAAE,QAAQ,EAAC,MAAM,YAAY,CAAC;AACzC,OAAO,EAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,eAAe,EAAC,MAAM,UAAU,CAAC;AACvE,OAAO,EAAgB,iBAAiB,EAAsB,QAAQ,IAAI,YAAY,EAAC,MAAM,eAAe,CAAC;AAC7G,OAAO,EAAC,YAAY,EAAC,MAAM,wBAAwB,CAAC;AAKpD,OAAO,EAAC,iBAAiB,EAAC,MAAM,iBAAiB,CAAC;AAClD,OAAO,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AkB,EAAE,MAAM,CAAC,CAAC;IACzD,CAAC;IAED,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,IAAI,EAAE,MAAM,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;IACnD,CAAC;CACF,CAAA;AAhOC;IADC,QAAQ,CAAC,KAAK,CAAC;;yCACG;AAGnB;IADC,QAAQ,CAAC,UAAU,CAAC;;8CACe;AAGpC;IADC,QAAQ,CAAC,WAAW,CAAC;;+CACe;AAGrC;IADC,QAAQ,CAAC,aAAa,EAAE,EAAE,CAAC;;4CACH;AAGzB;IADC,QAAQ,CAAC,MAAM,CAAC;;0CACY;AAG7B;IADC,QAAQ,CAAC,eAAe,CAAC;;kDACK;AAG/B;IADC,MAAM,EAAE;8BACW,QAAQ;8CAAC;AAG7B;IADC,MAAM,EAAE;8BACmB,gBAAgB;sDAAC;AAG7C;IADC,MAAM,EAAE;8BACW,YAAY;8CAAC;AAGjC;IADC,MAAM,EAAE;8BACW,eAAe;8CAAC;AAGpC;IADC,MAAM,EAAE;8BACM,mBAAmB;yCAAC;AAGnC;IADC,aAAa,EAAE;8BACC,eAAe;0CAAC;AArCtB,YAAY;IADxB,UAAU,EAAE;GACA,YAAY,CAoOxB;SApOY,YAAY","sourcesContent":["import {InjectContext, PlatformApplication, PlatformContext} from \"@tsed/common\";\nimport {Env, setValue} from \"@tsed/core\";\nimport {Constant, Inject, Injectable, InjectorService} from \"@tsed/di\";\nimport {Configuration, interactionPolicy, KoaContextWithOIDC, Provider as OIDCProvider} from \"oidc-provider\";\nimport {INTERACTIONS} from \"../constants/constants\";\nimport {InteractionMethods} from \"../domain/InteractionMethods\";\nimport {OidcAccountsMethods} from \"../domain/OidcAccountsMethods\";\nimport {OidcInteractionOptions} from \"../domain/OidcInteractionOptions\";\nimport {OidcSettings} from \"../domain/OidcSettings\";\nimport {OIDC_ERROR_EVENTS} from \"../utils/events\";\nimport {OidcAdapters} from \"./OidcAdapters\";\nimport {OidcInteractions} from \"./OidcInteractions\";\nimport {OidcJwks} from \"./OidcJwks\";\n\n@Injectable()\nexport class OidcProvider {\n raw: OIDCProvider;\n\n @Constant(\"env\")\n protected env: Env;\n\n @Constant(\"httpPort\")\n protected httpPort: number | string;\n\n @Constant(\"httpsPort\")\n protected httpsPort: number | string;\n\n @Constant(\"oidc.issuer\", \"\")\n protected issuer: string;\n\n @Constant(\"oidc\")\n protected oidc: OidcSettings;\n\n @Constant(\"PLATFORM_NAME\")\n protected platformName: string;\n\n @Inject()\n protected oidcJwks: OidcJwks;\n\n @Inject()\n protected oidcInteractions: OidcInteractions;\n\n @Inject()\n protected adapters: OidcAdapters;\n\n @Inject()\n protected injector: InjectorService;\n\n @Inject()\n protected app: PlatformApplication;\n\n @InjectContext()\n protected $ctx?: PlatformContext;\n\n hasConfiguration() {\n return !!this.oidc;\n }\n\n async getConfiguration(): Promise<Configuration> {\n const [jwks, adapter] = await Promise.all([this.oidcJwks.getJwks(), this.adapters.createAdapterClass()]);\n const {\n issuer,\n jwksPath,\n secureKey,\n proxy,\n Accounts,\n secureCookies = this.env == Env.PROD,\n Adapter,\n connectionName,\n ...options\n } = this.oidc;\n\n const configuration: Configuration = {\n interactions: {\n /* istanbul ignore next */\n url: (ctx, interaction) => `interaction/${interaction.uid}`\n },\n ...options,\n adapter,\n jwks\n };\n\n if (Accounts) {\n configuration.findAccount = (ctx, id, token) => this.injector.get<OidcAccountsMethods>(Accounts)!.findAccount(id, token);\n }\n\n if (secureCookies) {\n setValue(configuration, \"cookies.short.secure\", true);\n setValue(configuration, \"cookies.long.secure\", true);\n }\n\n const policy = this.getPolicy();\n if (policy) {\n setValue(configuration, \"interactions.policy\", policy);\n }\n\n const url = this.getInteractionsUrl();\n if (url) {\n setValue(configuration, \"interactions.url\", url);\n }\n\n return configuration;\n }\n\n getIssuer() {\n if (this.issuer) {\n return this.issuer;\n }\n\n // istanbul ignore next\n if (this.httpsPort) {\n return `https://localhost:${this.httpsPort}`;\n }\n\n return `http://localhost:${this.httpPort}`;\n }\n\n get(): OIDCProvider {\n return this.raw;\n }\n\n /**\n * Create a new instance of OidcProvider\n */\n async create(): Promise<void | OIDCProvider> {\n const {proxy = this.env === Env.PROD, secureKey, allowHttpLocalhost = this.env !== Env.PROD} = this.oidc;\n const configuration = await this.getConfiguration();\n\n await this.injector.alterAsync(\"$alterOidcConfiguration\", configuration);\n\n const oidcProvider = new OIDCProvider(this.getIssuer(), configuration);\n\n if (proxy) {\n // istanbul ignore next\n switch (this.platformName) {\n default:\n case \"express\":\n oidcProvider.proxy = true;\n break;\n case \"koa\":\n (this.app.rawApp as any).proxy = true;\n break;\n }\n }\n\n if (secureKey) {\n oidcProvider.app.keys = secureKey;\n }\n\n this.raw = oidcProvider;\n\n if (allowHttpLocalhost) {\n this.allowHttpLocalhost();\n }\n\n OIDC_ERROR_EVENTS.map((event) => {\n this.raw.on(event, this.createErrorHandler(event));\n });\n\n await this.injector.emit(\"$onCreateOIDC\", this.raw);\n\n return this.raw;\n }\n\n private createErrorHandler(event: string) {\n return (ctx: KoaContextWithOIDC, error: any, accountId?: string, sid?: string) => {\n this.logger.error({\n event: \"OIDC_ERROR\",\n type: event,\n error: {\n error_name: error.error,\n error_description: error.error_description,\n error_detail: error.error_detail\n },\n account_id: accountId,\n params: ctx.oidc.params,\n headers: ctx.headers,\n sid\n });\n\n // TODO see if we need to call platformExceptions\n // this.platformExceptions.catch(error, ctx.request.$ctx);\n };\n }\n\n public createPrompt(instance: InteractionMethods, options: OidcInteractionOptions) {\n const {checks: originalChecks = [], details, ...promptOptions} = options;\n const checks = [...(instance.checks ? instance.checks() : originalChecks)].filter(Boolean);\n\n return new interactionPolicy.Prompt(promptOptions, instance.details ? instance.details.bind(instance) : details, ...checks);\n }\n\n private getInteractionsUrl() {\n const provider = this.injector.getProviders().find((provider) => provider.subType === INTERACTIONS);\n\n if (provider) {\n return (ctx: any, interaction: any) => {\n // eslint-disable-line no-unused-vars\n return provider.path.replace(/:uid/, interaction.uid);\n };\n }\n }\n\n private allowHttpLocalhost() {\n const {invalidate: orig} = (this.raw.Client as any).Schema.prototype;\n\n (this.raw.Client as any).Schema.prototype.invalidate = function invalidate(message: string, code: string) {\n if (code === \"implicit-force-https\" || code === \"implicit-forbid-localhost\") {\n return;\n }\n\n /* istanbul ignore next */\n return orig.call(this, message);\n };\n }\n\n private getPolicy() {\n const policy = interactionPolicy.base();\n const interactions = this.oidcInteractions.getInteractions();\n\n if (interactions.length) {\n interactions.forEach((provider) => {\n const instance = this.injector.get<InteractionMethods>(provider.token)!;\n const options = provider.store.get(\"interactionOptions\");\n\n if (!policy.get(options.name)) {\n const prompt = this.createPrompt(instance, options);\n\n policy.add(prompt, options.priority);\n }\n\n if (instance.$onCreate) {\n instance.$onCreate(policy.get(options.name)!);\n }\n });\n }\n\n return this.injector.alter(\"$alterOidcPolicy\", policy);\n }\n\n get logger() {\n return this.$ctx?.logger || this.injector.logger;\n }\n}\n"]}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
export const OIDC_EVENTS = [
|
|
2
|
+
"access_token.destroyed",
|
|
3
|
+
"access_token.saved",
|
|
4
|
+
"access_token.issued",
|
|
5
|
+
"authorization_code.consumed",
|
|
6
|
+
"authorization_code.destroyed",
|
|
7
|
+
"authorization_code.saved",
|
|
8
|
+
"authorization.accepted",
|
|
9
|
+
"authorization.error",
|
|
10
|
+
"authorization.success",
|
|
11
|
+
"backchannel.error",
|
|
12
|
+
"backchannel.success",
|
|
13
|
+
"jwks.error",
|
|
14
|
+
"client_credentials.destroyed",
|
|
15
|
+
"client_credentials.saved",
|
|
16
|
+
"client_credentials.issued",
|
|
17
|
+
"device_code.consumed",
|
|
18
|
+
"device_code.destroyed",
|
|
19
|
+
"device_code.saved",
|
|
20
|
+
"discovery.error",
|
|
21
|
+
"end_session.error",
|
|
22
|
+
"end_session.success",
|
|
23
|
+
"grant.error",
|
|
24
|
+
"grant.revoked",
|
|
25
|
+
"grant.success",
|
|
26
|
+
"initial_access_token.destroyed",
|
|
27
|
+
"initial_access_token.saved",
|
|
28
|
+
"interaction.destroyed",
|
|
29
|
+
"interaction.ended",
|
|
30
|
+
"interaction.saved",
|
|
31
|
+
"interaction.started",
|
|
32
|
+
"introspection.error",
|
|
33
|
+
"replay_detection.destroyed",
|
|
34
|
+
"replay_detection.saved",
|
|
35
|
+
"pushed_authorization_request.error",
|
|
36
|
+
"pushed_authorization_request.success",
|
|
37
|
+
"pushed_authorization_request.destroyed",
|
|
38
|
+
"pushed_authorization_request.saved",
|
|
39
|
+
"refresh_token.consumed",
|
|
40
|
+
"refresh_token.destroyed",
|
|
41
|
+
"refresh_token.saved",
|
|
42
|
+
"registration_access_token.destroyed",
|
|
43
|
+
"registration_access_token.saved",
|
|
44
|
+
"registration_create.error",
|
|
45
|
+
"registration_create.success",
|
|
46
|
+
"registration_delete.error",
|
|
47
|
+
"registration_delete.success",
|
|
48
|
+
"registration_read.error",
|
|
49
|
+
"registration_update.error",
|
|
50
|
+
"registration_update.success",
|
|
51
|
+
"revocation.error",
|
|
52
|
+
"server_error",
|
|
53
|
+
"session.destroyed",
|
|
54
|
+
"session.saved",
|
|
55
|
+
"userinfo.error"
|
|
56
|
+
];
|
|
57
|
+
export const OIDC_ERROR_EVENTS = OIDC_EVENTS.filter((e) => e.includes("error"));
|
|
58
|
+
//# sourceMappingURL=events.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.js","sourceRoot":"","sources":["../../../src/utils/events.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,wBAAwB;IACxB,oBAAoB;IACpB,qBAAqB;IACrB,6BAA6B;IAC7B,8BAA8B;IAC9B,0BAA0B;IAC1B,wBAAwB;IACxB,qBAAqB;IACrB,uBAAuB;IACvB,mBAAmB;IACnB,qBAAqB;IACrB,YAAY;IACZ,8BAA8B;IAC9B,0BAA0B;IAC1B,2BAA2B;IAC3B,sBAAsB;IACtB,uBAAuB;IACvB,mBAAmB;IACnB,iBAAiB;IACjB,mBAAmB;IACnB,qBAAqB;IACrB,aAAa;IACb,eAAe;IACf,eAAe;IACf,gCAAgC;IAChC,4BAA4B;IAC5B,uBAAuB;IACvB,mBAAmB;IACnB,mBAAmB;IACnB,qBAAqB;IACrB,qBAAqB;IACrB,4BAA4B;IAC5B,wBAAwB;IACxB,oCAAoC;IACpC,sCAAsC;IACtC,wCAAwC;IACxC,oCAAoC;IACpC,wBAAwB;IACxB,yBAAyB;IACzB,qBAAqB;IACrB,qCAAqC;IACrC,iCAAiC;IACjC,2BAA2B;IAC3B,6BAA6B;IAC7B,2BAA2B;IAC3B,6BAA6B;IAC7B,yBAAyB;IACzB,2BAA2B;IAC3B,6BAA6B;IAC7B,kBAAkB;IAClB,cAAc;IACd,mBAAmB;IACnB,eAAe;IACf,gBAAgB;CACjB,CAAC;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC","sourcesContent":["export const OIDC_EVENTS = [\n \"access_token.destroyed\",\n \"access_token.saved\",\n \"access_token.issued\",\n \"authorization_code.consumed\",\n \"authorization_code.destroyed\",\n \"authorization_code.saved\",\n \"authorization.accepted\",\n \"authorization.error\",\n \"authorization.success\",\n \"backchannel.error\",\n \"backchannel.success\",\n \"jwks.error\",\n \"client_credentials.destroyed\",\n \"client_credentials.saved\",\n \"client_credentials.issued\",\n \"device_code.consumed\",\n \"device_code.destroyed\",\n \"device_code.saved\",\n \"discovery.error\",\n \"end_session.error\",\n \"end_session.success\",\n \"grant.error\",\n \"grant.revoked\",\n \"grant.success\",\n \"initial_access_token.destroyed\",\n \"initial_access_token.saved\",\n \"interaction.destroyed\",\n \"interaction.ended\",\n \"interaction.saved\",\n \"interaction.started\",\n \"introspection.error\",\n \"replay_detection.destroyed\",\n \"replay_detection.saved\",\n \"pushed_authorization_request.error\",\n \"pushed_authorization_request.success\",\n \"pushed_authorization_request.destroyed\",\n \"pushed_authorization_request.saved\",\n \"refresh_token.consumed\",\n \"refresh_token.destroyed\",\n \"refresh_token.saved\",\n \"registration_access_token.destroyed\",\n \"registration_access_token.saved\",\n \"registration_create.error\",\n \"registration_create.success\",\n \"registration_delete.error\",\n \"registration_delete.success\",\n \"registration_read.error\",\n \"registration_update.error\",\n \"registration_update.success\",\n \"revocation.error\",\n \"server_error\",\n \"session.destroyed\",\n \"session.saved\",\n \"userinfo.error\"\n];\n\nexport const OIDC_ERROR_EVENTS = OIDC_EVENTS.filter((e) => e.includes(\"error\"));\n"]}
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PlatformApplication } from "@tsed/common";
|
|
1
|
+
import { PlatformApplication, PlatformContext } from "@tsed/common";
|
|
2
2
|
import { Env } from "@tsed/core";
|
|
3
3
|
import { InjectorService } from "@tsed/di";
|
|
4
4
|
import { Configuration, interactionPolicy, Provider as OIDCProvider } from "oidc-provider";
|
|
@@ -21,6 +21,7 @@ export declare class OidcProvider {
|
|
|
21
21
|
protected adapters: OidcAdapters;
|
|
22
22
|
protected injector: InjectorService;
|
|
23
23
|
protected app: PlatformApplication;
|
|
24
|
+
protected $ctx?: PlatformContext;
|
|
24
25
|
hasConfiguration(): boolean;
|
|
25
26
|
getConfiguration(): Promise<Configuration>;
|
|
26
27
|
getIssuer(): string;
|
|
@@ -29,8 +30,10 @@ export declare class OidcProvider {
|
|
|
29
30
|
* Create a new instance of OidcProvider
|
|
30
31
|
*/
|
|
31
32
|
create(): Promise<void | OIDCProvider>;
|
|
33
|
+
private createErrorHandler;
|
|
32
34
|
createPrompt(instance: InteractionMethods, options: OidcInteractionOptions): interactionPolicy.Prompt;
|
|
33
35
|
private getInteractionsUrl;
|
|
34
36
|
private allowHttpLocalhost;
|
|
35
37
|
private getPolicy;
|
|
38
|
+
get logger(): import("@tsed/common").DILogger;
|
|
36
39
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/oidc-provider",
|
|
3
|
-
"version": "7.14.
|
|
3
|
+
"version": "7.14.2",
|
|
4
4
|
"description": "OIDC provider package for Ts.ED framework",
|
|
5
5
|
"private": false,
|
|
6
6
|
"source": "./src/index.ts",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"test": "cross-env NODE_ENV=test yarn jest --max-workers=2"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@tsed/adapters": "7.14.
|
|
25
|
+
"@tsed/adapters": "7.14.2",
|
|
26
26
|
"express-urlrewrite": "^1.4.0",
|
|
27
27
|
"jose2": "npm:jose@^2.0.4",
|
|
28
28
|
"koa-mount": "^4.0.0",
|
|
@@ -31,10 +31,10 @@
|
|
|
31
31
|
"uuid": "8.3.2"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@tsed/common": "7.14.
|
|
35
|
-
"@tsed/core": "7.14.
|
|
36
|
-
"@tsed/di": "7.14.
|
|
37
|
-
"@tsed/exceptions": "7.14.
|
|
34
|
+
"@tsed/common": "7.14.2",
|
|
35
|
+
"@tsed/core": "7.14.2",
|
|
36
|
+
"@tsed/di": "7.14.2",
|
|
37
|
+
"@tsed/exceptions": "7.14.2",
|
|
38
38
|
"@types/lowdb": "1.0.11",
|
|
39
39
|
"@types/oidc-provider": "^7.1.1",
|
|
40
40
|
"@types/uuid": "8.3.4",
|
|
@@ -42,12 +42,12 @@
|
|
|
42
42
|
"oidc-provider": "7.11.1"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
|
-
"@tsed/ajv": "^7.14.
|
|
46
|
-
"@tsed/common": "^7.14.
|
|
47
|
-
"@tsed/core": "^7.14.
|
|
48
|
-
"@tsed/di": "^7.14.
|
|
49
|
-
"@tsed/json-mapper": "^7.14.
|
|
50
|
-
"@tsed/schema": "^7.14.
|
|
45
|
+
"@tsed/ajv": "^7.14.2",
|
|
46
|
+
"@tsed/common": "^7.14.2",
|
|
47
|
+
"@tsed/core": "^7.14.2",
|
|
48
|
+
"@tsed/di": "^7.14.2",
|
|
49
|
+
"@tsed/json-mapper": "^7.14.2",
|
|
50
|
+
"@tsed/schema": "^7.14.2",
|
|
51
51
|
"oidc-provider": ">=7.3.0"
|
|
52
52
|
},
|
|
53
53
|
"peerDependenciesMeta": {
|