@tsed/oidc-provider 7.0.0-beta.9 → 7.0.0-rc.1

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.
Files changed (60) hide show
  1. package/coverage.json +6 -0
  2. package/jest.config.js +9 -0
  3. package/lib/cjs/OidcModule.js +7 -1
  4. package/lib/cjs/OidcModule.js.map +1 -1
  5. package/lib/cjs/domain/OidcAccountsMethods.js.map +1 -1
  6. package/lib/cjs/domain/OidcBadInteractionName.js +8 -0
  7. package/lib/cjs/domain/OidcBadInteractionName.js.map +1 -0
  8. package/lib/cjs/domain/OidcInteractionPromptProps.js +3 -0
  9. package/lib/cjs/domain/OidcInteractionPromptProps.js.map +1 -0
  10. package/lib/cjs/domain/OidcSettings.js.map +1 -1
  11. package/lib/cjs/index.js +2 -0
  12. package/lib/cjs/index.js.map +1 -1
  13. package/lib/cjs/middlewares/OidcInteractionMiddleware.js +5 -25
  14. package/lib/cjs/middlewares/OidcInteractionMiddleware.js.map +1 -1
  15. package/lib/cjs/services/OidcAdapters.js +22 -0
  16. package/lib/cjs/services/OidcAdapters.js.map +1 -1
  17. package/lib/cjs/services/OidcInteractionContext.js +61 -16
  18. package/lib/cjs/services/OidcInteractionContext.js.map +1 -1
  19. package/lib/cjs/services/OidcInteractions.js +8 -7
  20. package/lib/cjs/services/OidcInteractions.js.map +1 -1
  21. package/lib/cjs/services/OidcJwks.js +3 -0
  22. package/lib/cjs/services/OidcJwks.js.map +1 -1
  23. package/lib/cjs/services/OidcProvider.js +19 -7
  24. package/lib/cjs/services/OidcProvider.js.map +1 -1
  25. package/lib/esm/OidcModule.js +7 -1
  26. package/lib/esm/OidcModule.js.map +1 -1
  27. package/lib/esm/domain/OidcAccountsMethods.js.map +1 -1
  28. package/lib/esm/domain/OidcBadInteractionName.js +4 -0
  29. package/lib/esm/domain/OidcBadInteractionName.js.map +1 -0
  30. package/lib/esm/domain/OidcInteractionPromptProps.js +2 -0
  31. package/lib/esm/domain/OidcInteractionPromptProps.js.map +1 -0
  32. package/lib/esm/domain/OidcSettings.js.map +1 -1
  33. package/lib/esm/index.js +2 -0
  34. package/lib/esm/index.js.map +1 -1
  35. package/lib/esm/middlewares/OidcInteractionMiddleware.js +7 -27
  36. package/lib/esm/middlewares/OidcInteractionMiddleware.js.map +1 -1
  37. package/lib/esm/services/OidcAdapters.js +22 -0
  38. package/lib/esm/services/OidcAdapters.js.map +1 -1
  39. package/lib/esm/services/OidcInteractionContext.js +62 -17
  40. package/lib/esm/services/OidcInteractionContext.js.map +1 -1
  41. package/lib/esm/services/OidcInteractions.js +8 -7
  42. package/lib/esm/services/OidcInteractions.js.map +1 -1
  43. package/lib/esm/services/OidcJwks.js +3 -0
  44. package/lib/esm/services/OidcJwks.js.map +1 -1
  45. package/lib/esm/services/OidcProvider.js +20 -8
  46. package/lib/esm/services/OidcProvider.js.map +1 -1
  47. package/lib/types/OidcModule.d.ts +5 -5
  48. package/lib/types/domain/OidcAccountsMethods.d.ts +1 -2
  49. package/lib/types/domain/OidcBadInteractionName.d.ts +3 -0
  50. package/lib/types/domain/OidcInteractionPromptProps.d.ts +9 -0
  51. package/lib/types/domain/OidcSettings.d.ts +9 -1
  52. package/lib/types/index.d.ts +2 -0
  53. package/lib/types/middlewares/OidcInteractionMiddleware.d.ts +3 -5
  54. package/lib/types/services/OidcAdapters.d.ts +3 -2
  55. package/lib/types/services/OidcInteractionContext.d.ts +6 -2
  56. package/lib/types/services/OidcProvider.d.ts +3 -3
  57. package/package.json +15 -12
  58. package/readme.md +4 -2
  59. package/.mocharc.js +0 -5
  60. package/.nycrc +0 -27
package/coverage.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "statements": 99.69,
3
+ "branches": 94.82,
4
+ "functions": 98.71,
5
+ "lines": 99.67
6
+ }
package/jest.config.js ADDED
@@ -0,0 +1,9 @@
1
+ // For a detailed explanation regarding each configuration property, visit:
2
+ // https://jestjs.io/docs/en/configuration.html
3
+
4
+ module.exports = {
5
+ ...require("@tsed/jest-config")(__dirname, "oidc-provider"),
6
+ coverageThreshold: {
7
+ global: require("./coverage.json")
8
+ }
9
+ };
@@ -9,6 +9,11 @@ const OidcAdapters_1 = require("./services/OidcAdapters");
9
9
  const OidcJwks_1 = require("./services/OidcJwks");
10
10
  const OidcProvider_1 = require("./services/OidcProvider");
11
11
  let OidcModule = class OidcModule {
12
+ app;
13
+ platformName;
14
+ basePath;
15
+ oidcProvider;
16
+ injector;
12
17
  async $onInit() {
13
18
  if (this.oidcProvider.hasConfiguration()) {
14
19
  await this.oidcProvider.create();
@@ -34,8 +39,9 @@ let OidcModule = class OidcModule {
34
39
  }
35
40
  }
36
41
  $onReady() {
37
- if (this.oidcProvider.hasConfiguration() && this.injector.settings.getBestHost) {
42
+ if (this.oidcProvider.hasConfiguration() && "getBestHost" in this.injector.settings) {
38
43
  const { injector } = this;
44
+ // @ts-ignore
39
45
  const host = injector.settings.getBestHost();
40
46
  const url = host.toString();
41
47
  injector.logger.info(`WellKnown is available on ${url}/.well-known/openid-configuration`);
@@ -1 +1 @@
1
- {"version":3,"file":"OidcModule.js","sourceRoot":"","sources":["../../src/OidcModule.ts"],"names":[],"mappings":";;;;AAAA,yCAA0E;AAC1E,iCAA0C;AAC1C,kEAAiC;AACjC,0DAAqD;AACrD,kDAA6C;AAC7C,0DAAqD;AAKrD,IAAa,UAAU,GAAvB,MAAa,UAAU;IAgBrB,KAAK,CAAC,OAAO;QACX,IAAI,IAAI,CAAC,YAAY,CAAC,gBAAgB,EAAE,EAAE;YACxC,MAAM,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,CAAC;SAClC;IACH,CAAC;IAED,KAAK,CAAC,aAAa;QACjB,IAAI,IAAI,CAAC,QAAQ,KAAK,GAAG,EAAE;YACzB,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,IAAI,CAAC,oBAAoB,EAAE,CAAC,CAAC;SACjD;IACH,CAAC;IAED,KAAK,CAAC,gBAAgB;QACpB,IAAI,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AC;gBAC7D,OAAO,aAAa,CAAC,mBAAmB,EAAE,GAAG,IAAI,CAAC,QAAQ,iBAAiB,CAAC,CAAC;SAChF;IACH,CAAC;CACF,CAAA;AAhEC;IADC,IAAA,eAAM,GAAE;sCACJ,4BAAmB;uCAAC;AAGzB;IADC,IAAA,aAAQ,EAAC,eAAe,CAAC;;gDACL;AAGrB;IADC,IAAA,aAAQ,EAAC,WAAW,EAAE,OAAO,CAAC;;4CACd;AAGjB;IADC,IAAA,eAAM,GAAE;sCACK,2BAAY;gDAAC;AAG3B;IADC,IAAA,eAAM,GAAE;sCACC,wBAAe;4CAAC;AAdf,UAAU;IAHtB,IAAA,WAAM,EAAC;QACN,OAAO,EAAE,CAAC,2BAAY,EAAE,2BAAY,EAAE,mBAAQ,CAAC;KAChD,CAAC;GACW,UAAU,CAkEtB;AAlEY,gCAAU","sourcesContent":["import {Inject, InjectorService, PlatformApplication} from \"@tsed/common\";\nimport {Constant, Module} from \"@tsed/di\";\nimport koaMount from \"koa-mount\";\nimport {OidcAdapters} from \"./services/OidcAdapters\";\nimport {OidcJwks} from \"./services/OidcJwks\";\nimport {OidcProvider} from \"./services/OidcProvider\";\n\n@Module({\n imports: [OidcProvider, OidcAdapters, OidcJwks]\n})\nexport class OidcModule {\n @Inject()\n app: PlatformApplication;\n\n @Constant(\"PLATFORM_NAME\")\n platformName: string;\n\n @Constant(\"oidc.path\", \"/oidc\")\n basePath: string;\n\n @Inject()\n oidcProvider: OidcProvider;\n\n @Inject()\n injector: InjectorService;\n\n async $onInit() {\n if (this.oidcProvider.hasConfiguration()) {\n await this.oidcProvider.create();\n }\n }\n\n async $onRoutesInit() {\n if (this.basePath !== \"/\") {\n this.app.use(await this.getRewriteMiddleware());\n }\n }\n\n async $afterRoutesInit() {\n if (this.oidcProvider.hasConfiguration()) {\n const provider = this.oidcProvider.get();\n\n switch (this.platformName) {\n default:\n case \"express\":\n this.app.use(this.basePath, provider.callback());\n break;\n case \"koa\":\n this.app.use(koaMount(this.basePath, provider.app));\n break;\n }\n }\n }\n\n $onReady() {\n if (this.oidcProvider.hasConfiguration() && this.injector.settings.getBestHost) {\n const {injector} = this;\n const host = injector.settings.getBestHost();\n const url = host.toString();\n\n injector.logger.info(`WellKnown is available on ${url}/.well-known/openid-configuration`);\n }\n }\n\n private async getRewriteMiddleware() {\n switch (this.platformName) {\n default:\n case \"express\":\n const {default: expressUrlRewrite} = await import(\"express-urlrewrite\");\n return expressUrlRewrite(\"/.well-known/*\", `${this.basePath}/.well-known/$1`);\n case \"koa\":\n // @ts-ignore\n const {default: koaUrlRewrite} = await import(\"koa-rewrite\");\n return koaUrlRewrite(\"/.well-known/(.*)\", `${this.basePath}/.well-known/$1`);\n }\n }\n}\n"]}
1
+ {"version":3,"file":"OidcModule.js","sourceRoot":"","sources":["../../src/OidcModule.ts"],"names":[],"mappings":";;;;AAAA,yCAA0E;AAC1E,iCAA0C;AAC1C,kEAAiC;AACjC,0DAAqD;AACrD,kDAA6C;AAC7C,0DAAqD;AAKrD,IAAa,UAAU,GAAvB,MAAa,UAAU;IAEX,GAAG,CAAsB;IAGzB,YAAY,CAAS;IAGrB,QAAQ,CAAS;IAGjB,YAAY,CAAe;IAG3B,QAAQ,CAAkB;IAEpC,KAAK,CAAC,OAAO;QACX,IAAI,IAAI,CAAC,YAAY,CAAC,gBAAgB,EAAE,EAAE;YACxC,MAAM,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,CAAC;SAClC;IACH,CAAC;IAED,KAAK,CAAC,aAAa;QACjB,IAAI,IAAI,CAAC,QAAQ,KAAK,GAAG,EAAE;YACzB,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,IAAI,CAAC,oBAAoB,EAAE,CAAC,CAAC;SACjD;IACH,CAAC;IAED,KAAK,CAAC,gBAAgB;QACpB,IAAI,IAAI,CAAC,YAAY,CAAC,gBAAgB,EAAE,EAAE;YACxC,MAAM,QAAQ,GAAG,IAAI,CAAC,YAAY,CAAC,GAAG,EAAE,CA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H,CAAC;CACF,CAAA;AAjEC;IADC,IAAA,eAAM,GAAE;sCACM,4BAAmB;uCAAC;AAGnC;IADC,IAAA,aAAQ,EAAC,eAAe,CAAC;;gDACK;AAG/B;IADC,IAAA,aAAQ,EAAC,WAAW,EAAE,OAAO,CAAC;;4CACJ;AAG3B;IADC,IAAA,eAAM,GAAE;sCACe,2BAAY;gDAAC;AAGrC;IADC,IAAA,eAAM,GAAE;sCACW,wBAAe;4CAAC;AAdzB,UAAU;IAHtB,IAAA,WAAM,EAAC;QACN,OAAO,EAAE,CAAC,2BAAY,EAAE,2BAAY,EAAE,mBAAQ,CAAC;KAChD,CAAC;GACW,UAAU,CAmEtB;AAnEY,gCAAU","sourcesContent":["import {Inject, InjectorService, PlatformApplication} from \"@tsed/common\";\nimport {Constant, Module} from \"@tsed/di\";\nimport koaMount from \"koa-mount\";\nimport {OidcAdapters} from \"./services/OidcAdapters\";\nimport {OidcJwks} from \"./services/OidcJwks\";\nimport {OidcProvider} from \"./services/OidcProvider\";\n\n@Module({\n imports: [OidcProvider, OidcAdapters, OidcJwks]\n})\nexport class OidcModule {\n @Inject()\n protected app: PlatformApplication;\n\n @Constant(\"PLATFORM_NAME\")\n protected platformName: string;\n\n @Constant(\"oidc.path\", \"/oidc\")\n protected basePath: string;\n\n @Inject()\n protected oidcProvider: OidcProvider;\n\n @Inject()\n protected injector: InjectorService;\n\n async $onInit() {\n if (this.oidcProvider.hasConfiguration()) {\n await this.oidcProvider.create();\n }\n }\n\n async $onRoutesInit() {\n if (this.basePath !== \"/\") {\n this.app.use(await this.getRewriteMiddleware());\n }\n }\n\n async $afterRoutesInit() {\n if (this.oidcProvider.hasConfiguration()) {\n const provider = this.oidcProvider.get();\n\n switch (this.platformName) {\n default:\n case \"express\":\n this.app.use(this.basePath, provider.callback());\n break;\n case \"koa\":\n this.app.use(koaMount(this.basePath, provider.app));\n break;\n }\n }\n }\n\n $onReady() {\n if (this.oidcProvider.hasConfiguration() && \"getBestHost\" in this.injector.settings) {\n const {injector} = this;\n // @ts-ignore\n const host = injector.settings.getBestHost();\n const url = host.toString();\n\n injector.logger.info(`WellKnown is available on ${url}/.well-known/openid-configuration`);\n }\n }\n\n private async getRewriteMiddleware() {\n switch (this.platformName) {\n default:\n case \"express\":\n const {default: expressUrlRewrite} = await import(\"express-urlrewrite\");\n return expressUrlRewrite(\"/.well-known/*\", `${this.basePath}/.well-known/$1`);\n case \"koa\":\n // @ts-ignore\n const {default: koaUrlRewrite} = await import(\"koa-rewrite\");\n return koaUrlRewrite(\"/.well-known/(.*)\", `${this.basePath}/.well-known/$1`);\n }\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"OidcAccountsMethods.js","sourceRoot":"","sources":["../../../src/domain/OidcAccountsMethods.ts"],"names":[],"mappings":"","sourcesContent":["import {PlatformContext} from \"@tsed/common\";\nimport {Provider, Account} from \"oidc-provider\";\n\nexport type AuthorizationCode = InstanceType<Provider[\"AuthorizationCode\"]>;\nexport type AccessToken = InstanceType<Provider[\"AccessToken\"]>;\nexport type DeviceCode = InstanceType<Provider[\"DeviceCode\"]>;\nexport type BackchannelAuthenticationRequest = InstanceType<Provider[\"BackchannelAuthenticationRequest\"]>;\n\nexport interface OidcAccountsMethods {\n findAccount(\n id: string,\n token: AuthorizationCode | AccessToken | DeviceCode | BackchannelAuthenticationRequest | undefined,\n ctx: PlatformContext\n ): Promise<Account | undefined>;\n}\n"]}
1
+ {"version":3,"file":"OidcAccountsMethods.js","sourceRoot":"","sources":["../../../src/domain/OidcAccountsMethods.ts"],"names":[],"mappings":"","sourcesContent":["import {Provider, Account} from \"oidc-provider\";\n\nexport type AuthorizationCode = InstanceType<Provider[\"AuthorizationCode\"]>;\nexport type AccessToken = InstanceType<Provider[\"AccessToken\"]>;\nexport type DeviceCode = InstanceType<Provider[\"DeviceCode\"]>;\nexport type BackchannelAuthenticationRequest = InstanceType<Provider[\"BackchannelAuthenticationRequest\"]>;\n\nexport interface OidcAccountsMethods {\n findAccount(\n id: string,\n token: AuthorizationCode | AccessToken | DeviceCode | BackchannelAuthenticationRequest | undefined\n ): Promise<Account | undefined>;\n}\n"]}
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OidcBadInteractionName = void 0;
4
+ const exceptions_1 = require("@tsed/exceptions");
5
+ class OidcBadInteractionName extends exceptions_1.BadRequest {
6
+ }
7
+ exports.OidcBadInteractionName = OidcBadInteractionName;
8
+ //# sourceMappingURL=OidcBadInteractionName.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OidcBadInteractionName.js","sourceRoot":"","sources":["../../../src/domain/OidcBadInteractionName.ts"],"names":[],"mappings":";;;AAAA,iDAA4C;AAE5C,MAAa,sBAAuB,SAAQ,uBAAU;CAAG;AAAzD,wDAAyD","sourcesContent":["import {BadRequest} from \"@tsed/exceptions\";\n\nexport class OidcBadInteractionName extends BadRequest {}\n"]}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=OidcInteractionPromptProps.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OidcInteractionPromptProps.js","sourceRoot":"","sources":["../../../src/domain/OidcInteractionPromptProps.ts"],"names":[],"mappings":"","sourcesContent":["import {UnknownObject} from \"oidc-provider\";\nimport {OidcClient} from \"./interfaces\";\n\nexport type OidcInteractionPromptProps<Props = Record<string, any>> = {\n client: OidcClient;\n uid: string;\n grantId: string;\n details: UnknownObject;\n params: Record<string, any>;\n} & Props;\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"OidcSettings.js","sourceRoot":"","sources":["../../../src/domain/OidcSettings.ts"],"names":[],"mappings":"","sourcesContent":["import {Type} from \"@tsed/core\";\nimport {JwksKeyParameters} from \"@tsed/jwks\";\nimport {Configuration} from \"oidc-provider\";\nimport {OidcAccountsMethods} from \"./OidcAccountsMethods\";\n\nexport interface OidcSettings extends Configuration {\n /**\n * Path on which the oidc-provider instance is mounted.\n */\n path?: string;\n /**\n * Issuer URI. By default Ts.ED create issuer with http://localhost:${httpPort}\n */\n issuer?: string;\n /**\n * Path to store jwks keys.\n */\n jwksPath?: string;\n /**\n * Generate jwks from given certificates\n */\n certificates?: JwksKeyParameters[];\n /**\n * Secure keys.\n */\n secureKey?: string[];\n /**\n * Enable proxy.\n */\n proxy?: boolean;\n /**\n * Injectable service to manage accounts.\n */\n Accounts?: Type<OidcAccountsMethods>;\n /**\n * Injectable service to manage clients.\n */\n // Clients?: Type<OidcClientsMethods>;\n}\n\ndeclare global {\n namespace TsED {\n interface Configuration {\n oidc: OidcSettings;\n }\n }\n}\n"]}
1
+ {"version":3,"file":"OidcSettings.js","sourceRoot":"","sources":["../../../src/domain/OidcSettings.ts"],"names":[],"mappings":"","sourcesContent":["import {Type} from \"@tsed/core\";\nimport {JwksKeyParameters} from \"@tsed/jwks\";\nimport {Configuration} from \"oidc-provider\";\nimport {OidcAccountsMethods} from \"./OidcAccountsMethods\";\n\nexport interface OidcSettings extends Configuration {\n /**\n * force the secure cookie. By default, in dev mode it's disabled and in production it's enabled.\n */\n secureCookies?: boolean;\n /**\n * Path on which the oidc-provider instance is mounted.\n */\n path?: string;\n /**\n * Issuer URI. By default, Ts.ED create issuer with http://localhost:${httpPort}\n */\n issuer?: string;\n /**\n * Path to store jwks keys.\n */\n jwksPath?: string;\n /**\n * Generate jwks from given certificates\n */\n certificates?: JwksKeyParameters[];\n /**\n * Secure keys.\n */\n secureKey?: string[];\n /**\n * Enable proxy.\n */\n proxy?: boolean;\n /**\n * Allow redirect_uri on HTTP protocol and localhost domain.\n */\n allowHttpLocalhost?: boolean;\n /**\n * Injectable service to manage accounts.\n */\n Accounts?: Type<OidcAccountsMethods>;\n}\n\ndeclare global {\n namespace TsED {\n interface Configuration {\n oidc: OidcSettings;\n }\n }\n}\n"]}
package/lib/cjs/index.js CHANGED
@@ -16,9 +16,11 @@ tslib_1.__exportStar(require("./decorators/params"), exports);
16
16
  tslib_1.__exportStar(require("./decorators/prompt"), exports);
17
17
  tslib_1.__exportStar(require("./decorators/uid"), exports);
18
18
  tslib_1.__exportStar(require("./domain/OidcAccountsMethods"), exports);
19
+ tslib_1.__exportStar(require("./domain/OidcBadInteractionName"), exports);
19
20
  tslib_1.__exportStar(require("./domain/OidcInteraction"), exports);
20
21
  tslib_1.__exportStar(require("./domain/OidcInteractionMethods"), exports);
21
22
  tslib_1.__exportStar(require("./domain/OidcInteractionOptions"), exports);
23
+ tslib_1.__exportStar(require("./domain/OidcInteractionPromptProps"), exports);
22
24
  tslib_1.__exportStar(require("./domain/OidcSettings"), exports);
23
25
  tslib_1.__exportStar(require("./domain/interfaces"), exports);
24
26
  tslib_1.__exportStar(require("./middlewares/OidcInteractionMiddleware"), exports);
@@ -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,uEAA6C;AAC7C,mEAAyC;AACzC,0EAAgD;AAChD,0EAAgD;AAChD,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/OidcAccountsMethods\";\nexport * from \"./domain/OidcInteraction\";\nexport * from \"./domain/OidcInteractionMethods\";\nexport * from \"./domain/OidcInteractionOptions\";\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,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/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"]}
@@ -3,37 +3,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.OidcInteractionMiddleware = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const common_1 = require("@tsed/common");
6
- const constants_1 = require("../constants/constants");
7
6
  const OidcInteractionContext_1 = require("../services/OidcInteractionContext");
8
- const OidcInteractions_1 = require("../services/OidcInteractions");
9
7
  let OidcInteractionMiddleware = class OidcInteractionMiddleware {
10
- async use(context) {
11
- const oidcInteraction = this.injector.invoke(OidcInteractionContext_1.OidcInteractionContext, context.container);
12
- const interactionDetails = await oidcInteraction.interactionDetails();
13
- const { uid, prompt, params, session, grantId } = interactionDetails;
14
- context.set(constants_1.INTERACTION_CONTEXT, oidcInteraction);
15
- context.set(constants_1.INTERACTION_DETAILS, interactionDetails);
16
- context.set(constants_1.INTERACTION_UID, uid);
17
- context.set(constants_1.INTERACTION_PROMPT, prompt);
18
- context.set(constants_1.INTERACTION_PARAMS, params);
19
- context.set(constants_1.INTERACTION_GRANT_ID, grantId);
20
- context.set(constants_1.INTERACTION_SESSION, session);
8
+ oidcInteractionContext;
9
+ async use() {
10
+ await this.oidcInteractionContext.interactionDetails();
21
11
  }
22
12
  };
23
13
  tslib_1.__decorate([
24
14
  (0, common_1.Inject)(),
25
- tslib_1.__metadata("design:type", OidcInteractions_1.OidcInteractions)
26
- ], OidcInteractionMiddleware.prototype, "oidcInteractions", void 0);
27
- tslib_1.__decorate([
28
- (0, common_1.Inject)(),
29
- tslib_1.__metadata("design:type", common_1.InjectorService)
30
- ], OidcInteractionMiddleware.prototype, "injector", void 0);
31
- tslib_1.__decorate([
32
- tslib_1.__param(0, (0, common_1.Context)()),
33
- tslib_1.__metadata("design:type", Function),
34
- tslib_1.__metadata("design:paramtypes", [Object]),
35
- tslib_1.__metadata("design:returntype", Promise)
36
- ], OidcInteractionMiddleware.prototype, "use", null);
15
+ tslib_1.__metadata("design:type", OidcInteractionContext_1.OidcInteractionContext)
16
+ ], OidcInteractionMiddleware.prototype, "oidcInteractionContext", void 0);
37
17
  OidcInteractionMiddleware = tslib_1.__decorate([
38
18
  (0, common_1.Middleware)()
39
19
  ], OidcInteractionMiddleware);
@@ -1 +1 @@
1
- {"version":3,"file":"OidcInteractionMiddleware.js","sourceRoot":"","sources":["../../../src/middlewares/OidcInteractionMiddleware.ts"],"names":[],"mappings":";;;;AAAA,yCAA0E;AAC1E,sDAQgC;AAChC,+EAA0E;AAC1E,mEAA8D;AAG9D,IAAa,yBAAyB,GAAtC,MAAa,yBAAyB;IAOpC,KAAK,CAAC,GAAG,CAAY,OAAgB;QACnC,MAAM,eAAe,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAyB,+CAAsB,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;QAChH,MAAM,kBAAkB,GAAG,MAAM,eAAe,CAAC,kBAAkB,EAAE,CAAC;QACtE,MAAM,EAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAC,GAAG,kBAAyB,CAAC;QAE1E,OAAO,CAAC,GAAG,CAAC,+BAAmB,EAAE,eAAe,CAAC,CAAC;QAClD,OAAO,CAAC,GAAG,CAAC,+BAAmB,EAAE,kBAAkB,CAAC,CAAC;QACrD,OAAO,CAAC,GAAG,CAAC,2BAAe,EAAE,GAAG,CAAC,CAAC;QAClC,OAAO,CAAC,GAAG,CAAC,8BAAkB,EAAE,MAAM,CAAC,CAAC;QACxC,OAAO,CAAC,GAAG,CAAC,8BAAkB,EAAE,MAAM,CAAC,CAAC;QACxC,OAAO,CAAC,GAAG,CAAC,gCAAoB,EAAE,OAAO,CAAC,CAAC;QAC3C,OAAO,CAAC,GAAG,CAAC,+BAAmB,EAAE,OAAO,CAAC,CAAC;IAC5C,CAAC;CACF,CAAA;AAlBC;IADC,IAAA,eAAM,GAAE;sCACmB,mCAAgB;mEAAC;AAG7C;IADC,IAAA,eAAM,GAAE;sCACW,wBAAe;2DAAC;AAEpC;IAAW,mBAAA,IAAA,gBAAO,GAAE,CAAA;;;;oDAYnB;AAnBU,yBAAyB;IADrC,IAAA,mBAAU,GAAE;GACA,yBAAyB,CAoBrC;AApBY,8DAAyB","sourcesContent":["import {Context, Inject, InjectorService, Middleware} from \"@tsed/common\";\nimport {\n INTERACTION_CONTEXT,\n INTERACTION_DETAILS,\n INTERACTION_PARAMS,\n INTERACTION_GRANT_ID,\n INTERACTION_PROMPT,\n INTERACTION_SESSION,\n INTERACTION_UID\n} from \"../constants/constants\";\nimport {OidcInteractionContext} from \"../services/OidcInteractionContext\";\nimport {OidcInteractions} from \"../services/OidcInteractions\";\n\n@Middleware()\nexport class OidcInteractionMiddleware {\n @Inject()\n protected oidcInteractions: OidcInteractions;\n\n @Inject()\n protected injector: InjectorService;\n\n async use(@Context() context: Context) {\n const oidcInteraction = this.injector.invoke<OidcInteractionContext>(OidcInteractionContext, context.container);\n const interactionDetails = await oidcInteraction.interactionDetails();\n const {uid, prompt, params, session, grantId} = interactionDetails as any;\n\n context.set(INTERACTION_CONTEXT, oidcInteraction);\n context.set(INTERACTION_DETAILS, interactionDetails);\n context.set(INTERACTION_UID, uid);\n context.set(INTERACTION_PROMPT, prompt);\n context.set(INTERACTION_PARAMS, params);\n context.set(INTERACTION_GRANT_ID, grantId);\n context.set(INTERACTION_SESSION, session);\n }\n}\n"]}
1
+ {"version":3,"file":"OidcInteractionMiddleware.js","sourceRoot":"","sources":["../../../src/middlewares/OidcInteractionMiddleware.ts"],"names":[],"mappings":";;;;AAAA,yCAAgD;AAChD,+EAA0E;AAG1E,IAAa,yBAAyB,GAAtC,MAAa,yBAAyB;IAE1B,sBAAsB,CAAyB;IAEzD,KAAK,CAAC,GAAG;QACP,MAAM,IAAI,CAAC,sBAAsB,CAAC,kBAAkB,EAAE,CAAC;IACzD,CAAC;CACF,CAAA;AALC;IADC,IAAA,eAAM,GAAE;sCACyB,+CAAsB;yEAAC;AAF9C,yBAAyB;IADrC,IAAA,mBAAU,GAAE;GACA,yBAAyB,CAOrC;AAPY,8DAAyB","sourcesContent":["import {Inject, Middleware} from \"@tsed/common\";\nimport {OidcInteractionContext} from \"../services/OidcInteractionContext\";\n\n@Middleware()\nexport class OidcInteractionMiddleware {\n @Inject()\n protected oidcInteractionContext: OidcInteractionContext;\n\n async use() {\n await this.oidcInteractionContext.interactionDetails();\n }\n}\n"]}
@@ -5,9 +5,11 @@ const tslib_1 = require("tslib");
5
5
  const adapters_1 = require("@tsed/adapters");
6
6
  const di_1 = require("@tsed/di");
7
7
  let OidcAdapters = class OidcAdapters {
8
+ adapters;
8
9
  createAdapterClass() {
9
10
  const self = this;
10
11
  return class CustomAdapter {
12
+ adapter;
11
13
  constructor(name) {
12
14
  this.adapter = self.adapters.invokeAdapter({
13
15
  collectionName: name,
@@ -25,22 +27,42 @@ let OidcAdapters = class OidcAdapters {
25
27
  return this.adapter.findById(id);
26
28
  }
27
29
  async findByUserCode(userCode) {
30
+ // istanbul ignore next
31
+ if (this.adapter.findByUserCode) {
32
+ return this.adapter.findByUserCode(userCode);
33
+ }
28
34
  return this.adapter.findOne({
29
35
  userCode
30
36
  });
31
37
  }
32
38
  async findByUid(uid) {
39
+ // istanbul ignore next
40
+ if (this.adapter.findByUid) {
41
+ return this.adapter.findByUid(uid);
42
+ }
33
43
  return this.adapter.findOne({
34
44
  uid
35
45
  });
36
46
  }
37
47
  async destroy(id) {
48
+ // istanbul ignore next
49
+ if (this.adapter.destroy) {
50
+ return this.adapter.destroy(id);
51
+ }
38
52
  await this.adapter.deleteById(id);
39
53
  }
40
54
  async revokeByGrantId(grantId) {
55
+ // istanbul ignore next
56
+ if (this.adapter.revokeByGrantId) {
57
+ return this.adapter.revokeByGrantId(grantId);
58
+ }
41
59
  await this.adapter.deleteMany({ grantId });
42
60
  }
43
61
  async consume(grantId) {
62
+ // istanbul ignore next
63
+ if (this.adapter.consume) {
64
+ return this.adapter.consume(grantId);
65
+ }
44
66
  await this.adapter.update(grantId, { consumed: Math.floor(Date.now() / 1000) });
45
67
  }
46
68
  };
@@ -1 +1 @@
1
- {"version":3,"file":"OidcAdapters.js","sourceRoot":"","sources":["../../../src/services/OidcAdapters.ts"],"names":[],"mappings":";;;;AAAA,6CAAiD;AACjD,iCAA4C;AAI5C,IAAa,YAAY,GAAzB,MAAa,YAAY;IAIvB,kBAAkB;QAChB,MAAM,IAAI,GAAG,IAAI,CAAC;QAElB,OAAO,MAAM,aAAa;YAGxB,YAAY,IAAY;gBACtB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAM;oBAC9C,cAAc,EAAE,IAAI;oBACpB,KAAK,EAAE,MAAM;iBACd,CAAC,CAAC;YACL,CAAC;YAED,KAAK,CAAC,MAAM,CAAC,EAAU,EAAE,OAAY,EAAE,SAAiB;gBACtD,IAAI,SAAS,CAAC;gBAEd,IAAI,SAAS,EAAE;oBACb,SAAS,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,GAAG,IAAI,CAAC,CAAC;iBACrD;gBAED,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;YACpD,CAAC;YAED,KAAK,CAAC,IAAI,CAAC,EAAU;gBACnB,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;YACnC,CAAC;YAED,KAAK,CAAC,cAAc,CAAC,QAAgB;gBACnC,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC;oBAC1B,QAAQ;iBACT,CAAC,CAAC;YACL,CAAC;YAED,KAAK,CAAC,SAAS,CAAC,GAAW;gBACzB,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC;oBAC1B,GAAG;iBACJ,CAAC,CAAC;YACL,CAAC;YAED,KAAK,CAAC,OAAO,CAAC,EAAU;gBACtB,MAAM,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;YACpC,CAAC;YAED,KAAK,CAAC,eAAe,CAAC,OAAe;gBACnC,MAAM,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,EAAC,OAAO,EAAC,CAAC,CAAC;YAC3C,CAAC;YAED,KAAK,CAAC,OAAO,CAAC,OAAe;gBAC3B,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,EAAC,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,EAAC,CAAC,CAAC;YAChF,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAA;AAtDC;IADC,IAAA,WAAM,GAAE;sCACW,mBAAQ;8CAAC;AAFlB,YAAY;IADxB,IAAA,eAAU,GAAE;GACA,YAAY,CAwDxB;AAxDY,oCAAY","sourcesContent":["import {Adapter, Adapters} from \"@tsed/adapters\";\nimport {Inject, Injectable} from \"@tsed/di\";\nimport {Adapter as OidcAdapter, AdapterConstructor} from \"oidc-provider\";\n\n@Injectable()\nexport class OidcAdapters {\n @Inject()\n protected adapters: Adapters;\n\n createAdapterClass(): AdapterConstructor {\n const self = this;\n\n return class CustomAdapter implements OidcAdapter {\n adapter: Adapter<any>;\n\n constructor(name: string) {\n this.adapter = self.adapters.invokeAdapter<any>({\n collectionName: name,\n model: Object\n });\n }\n\n async upsert(id: string, payload: any, expiresIn: number): Promise<void> {\n let expiresAt;\n\n if (expiresIn) {\n expiresAt = new Date(Date.now() + expiresIn * 1000);\n }\n\n await this.adapter.upsert(id, payload, expiresAt);\n }\n\n async find(id: string) {\n return this.adapter.findById(id);\n }\n\n async findByUserCode(userCode: string) {\n return this.adapter.findOne({\n userCode\n });\n }\n\n async findByUid(uid: string) {\n return this.adapter.findOne({\n uid\n });\n }\n\n async destroy(id: string) {\n await this.adapter.deleteById(id);\n }\n\n async revokeByGrantId(grantId: string) {\n await this.adapter.deleteMany({grantId});\n }\n\n async consume(grantId: string) {\n await this.adapter.update(grantId, {consumed: Math.floor(Date.now() / 1000)});\n }\n };\n }\n}\n"]}
1
+ {"version":3,"file":"OidcAdapters.js","sourceRoot":"","sources":["../../../src/services/OidcAdapters.ts"],"names":[],"mappings":";;;;AAAA,6CAAiD;AACjD,iCAA4C;AAM5C,IAAa,YAAY,GAAzB,MAAa,YAAY;IAEb,QAAQ,CAAW;IAE7B,kBAAkB;QAChB,MAAM,IAAI,GAAG,IAAI,CAAC;QAElB,OAAO,MAAM,aAAa;YACxB,OAAO,CAAqB;YAE5B,YAAY,IAAY;gBACtB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAM;oBAC9C,cAAc,EAAE,IAAI;oBACpB,KAAK,EAAE,MAAM;iBACd,CAAuB,CAAC;YAC3B,CAAC;YAED,KAAK,CAAC,MAAM,CAAC,EAAU,EAAE,OAAY,EAAE,SAAiB;gBACtD,IAAI,SAAS,CAAC;gBAEd,IAAI,SAAS,EAAE;oBACb,SAAS,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,GAAG,IAAI,CAAC,CAAC;iBACrD;gBAED,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;YACpD,CAAC;YAED,KAAK,CAAC,IAAI,CAAC,EAAU;gBACnB,OAAO,IAAI,CAAC,OAAO,C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C,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;iBACtC;gBAED,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,EAAC,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,EAAC,CAAC,CAAC;YAChF,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAA;AA/EC;IADC,IAAA,WAAM,GAAE;sCACW,mBAAQ;8CAAC;AAFlB,YAAY;IADxB,IAAA,eAAU,GAAE;GACA,YAAY,CAiFxB;AAjFY,oCAAY","sourcesContent":["import {Adapter, Adapters} from \"@tsed/adapters\";\nimport {Inject, Injectable} from \"@tsed/di\";\nimport {Adapter as OidcAdapter, AdapterConstructor} from \"oidc-provider\";\n\nexport type OidcAdapterMethods<Model = any> = Adapter<Model> & Partial<Omit<OidcAdapter, \"upsert\">>;\n\n@Injectable()\nexport class OidcAdapters {\n @Inject()\n protected adapters: Adapters;\n\n createAdapterClass(): AdapterConstructor {\n const self = this;\n\n return class CustomAdapter implements OidcAdapter {\n adapter: OidcAdapterMethods;\n\n constructor(name: string) {\n this.adapter = self.adapters.invokeAdapter<any>({\n collectionName: name,\n model: Object\n }) as OidcAdapterMethods;\n }\n\n async upsert(id: string, payload: any, expiresIn: number): Promise<void> {\n let expiresAt;\n\n if (expiresIn) {\n expiresAt = new Date(Date.now() + expiresIn * 1000);\n }\n\n await this.adapter.upsert(id, payload, expiresAt);\n }\n\n async find(id: string) {\n return this.adapter.findById(id);\n }\n\n async findByUserCode(userCode: string) {\n // istanbul ignore next\n if (this.adapter.findByUserCode) {\n return this.adapter.findByUserCode(userCode);\n }\n\n return this.adapter.findOne({\n userCode\n });\n }\n\n async findByUid(uid: string) {\n // istanbul ignore next\n if (this.adapter.findByUid) {\n return this.adapter.findByUid(uid);\n }\n\n return this.adapter.findOne({\n uid\n });\n }\n\n async destroy(id: string) {\n // istanbul ignore next\n if (this.adapter.destroy) {\n return this.adapter.destroy(id);\n }\n\n await this.adapter.deleteById(id);\n }\n\n async revokeByGrantId(grantId: string) {\n // istanbul ignore next\n if (this.adapter.revokeByGrantId) {\n return this.adapter.revokeByGrantId(grantId);\n }\n\n await this.adapter.deleteMany({grantId});\n }\n\n async consume(grantId: string) {\n // istanbul ignore next\n if (this.adapter.consume) {\n return this.adapter.consume(grantId);\n }\n\n await this.adapter.update(grantId, {consumed: Math.floor(Date.now() / 1000)});\n }\n };\n }\n}\n"]}
@@ -5,10 +5,20 @@ const tslib_1 = require("tslib");
5
5
  const common_1 = require("@tsed/common");
6
6
  const core_1 = require("@tsed/core");
7
7
  const di_1 = require("@tsed/di");
8
+ const exceptions_1 = require("@tsed/exceptions");
9
+ const constants_1 = require("../constants/constants");
10
+ const OidcBadInteractionName_1 = require("../domain/OidcBadInteractionName");
8
11
  const debug_1 = require("../utils/debug");
9
12
  const OidcInteractions_1 = require("./OidcInteractions");
10
13
  const OidcProvider_1 = require("./OidcProvider");
11
14
  let OidcInteractionContext = class OidcInteractionContext {
15
+ env;
16
+ oidcProvider;
17
+ oidcInteractions;
18
+ $ctx;
19
+ get raw() {
20
+ return this.$ctx.get(constants_1.INTERACTION_DETAILS);
21
+ }
12
22
  get session() {
13
23
  return this.raw.session;
14
24
  }
@@ -27,40 +37,65 @@ let OidcInteractionContext = class OidcInteractionContext {
27
37
  async runInteraction(name = this.prompt.name) {
28
38
  const handler = this.oidcInteractions.getInteractionHandler(name);
29
39
  if (handler) {
30
- await handler(this.context);
40
+ await handler(this.$ctx);
31
41
  }
32
42
  }
33
43
  async interactionDetails() {
34
- this.raw = await this.oidcProvider.get().interactionDetails(this.context.getReq(), this.context.getRes());
35
- return this.raw;
44
+ const raw = await this.oidcProvider.get().interactionDetails(this.$ctx.getReq(), this.$ctx.getRes());
45
+ const { uid, prompt, params, session, grantId } = raw;
46
+ this.$ctx.set(constants_1.INTERACTION_CONTEXT, this);
47
+ this.$ctx.set(constants_1.INTERACTION_DETAILS, raw);
48
+ this.$ctx.set(constants_1.INTERACTION_UID, uid);
49
+ this.$ctx.set(constants_1.INTERACTION_PROMPT, prompt);
50
+ this.$ctx.set(constants_1.INTERACTION_PARAMS, params);
51
+ this.$ctx.set(constants_1.INTERACTION_GRANT_ID, grantId);
52
+ this.$ctx.set(constants_1.INTERACTION_SESSION, session);
53
+ return raw;
36
54
  }
37
55
  async interactionFinished(result, options = { mergeWithLastSubmission: false }) {
38
- return this.oidcProvider.get().interactionFinished(this.context.getReq(), this.context.getRes(), result, options);
56
+ return this.oidcProvider.get().interactionFinished(this.$ctx.getReq(), this.$ctx.getRes(), result, options);
39
57
  }
40
58
  async interactionResult(result, options = { mergeWithLastSubmission: false }) {
41
- return this.oidcProvider.get().interactionResult(this.context.getReq(), this.context.getRes(), result, options);
59
+ return this.oidcProvider.get().interactionResult(this.$ctx.getReq(), this.$ctx.getRes(), result, options);
60
+ }
61
+ async interactionPrompt(options) {
62
+ const client = await this.findClient();
63
+ return {
64
+ client,
65
+ uid: this.uid,
66
+ grantId: this.grantId,
67
+ details: this.prompt.details,
68
+ params: {
69
+ ...this.params,
70
+ ...options.params
71
+ },
72
+ ...options,
73
+ ...this.debug()
74
+ };
42
75
  }
43
76
  async render(view, result) {
44
- return this.context.response.render(view, result);
77
+ return this.$ctx.response.render(view, result);
45
78
  }
46
79
  async save(ttl) {
47
80
  return this.raw.save(ttl);
48
81
  }
49
82
  async findClient(clientId = this.params.client_id) {
50
- return this.oidcProvider.get().Client.find(clientId);
83
+ const key = `$client:${clientId}`;
84
+ return this.$ctx.cacheAsync(key, () => this.oidcProvider.get().Client.find(clientId));
51
85
  }
52
86
  async findAccount(sub, token) {
53
- var _a;
54
87
  if (!sub && this.session) {
55
- sub = (_a = this.session) === null || _a === void 0 ? void 0 : _a.accountId;
88
+ sub = this.session?.accountId;
56
89
  }
57
90
  if (!sub) {
58
91
  return;
59
92
  }
60
- return this.oidcProvider.get().Account.findAccount(undefined, sub, token);
93
+ const key = `$account:${sub}`;
94
+ return this.$ctx.cacheAsync(key, (() => {
95
+ return this.oidcProvider.get().Account.findAccount(undefined, sub, token);
96
+ }));
61
97
  }
62
98
  async getGrant() {
63
- var _a;
64
99
  const { Grant } = this.oidcProvider.get();
65
100
  if (this.grantId) {
66
101
  // we'll be modifying existing grant in existing session
@@ -68,10 +103,21 @@ let OidcInteractionContext = class OidcInteractionContext {
68
103
  return await (this.oidcProvider.get().find || Grant.find)(this.grantId);
69
104
  }
70
105
  return new Grant({
71
- accountId: (_a = this.session) === null || _a === void 0 ? void 0 : _a.accountId,
106
+ accountId: this.session?.accountId,
72
107
  clientId: this.params.client_id
73
108
  });
74
109
  }
110
+ checkInteractionName(name) {
111
+ if (this.prompt.name !== name) {
112
+ throw new OidcBadInteractionName_1.OidcBadInteractionName("Bad interaction name");
113
+ }
114
+ }
115
+ async checkClientId(clientId = this.params.client_id) {
116
+ const client = await this.findClient(clientId);
117
+ if (!client) {
118
+ throw new exceptions_1.Unauthorized(`Unknown client_id ${clientId}`);
119
+ }
120
+ }
75
121
  debug(obj) {
76
122
  /* istanbul ignore next */
77
123
  if (this.env === core_1.Env.PROD) {
@@ -102,12 +148,11 @@ tslib_1.__decorate([
102
148
  tslib_1.__metadata("design:type", OidcInteractions_1.OidcInteractions)
103
149
  ], OidcInteractionContext.prototype, "oidcInteractions", void 0);
104
150
  tslib_1.__decorate([
105
- (0, di_1.Inject)(),
151
+ (0, common_1.InjectContext)(),
106
152
  tslib_1.__metadata("design:type", common_1.PlatformContext)
107
- ], OidcInteractionContext.prototype, "context", void 0);
153
+ ], OidcInteractionContext.prototype, "$ctx", void 0);
108
154
  OidcInteractionContext = tslib_1.__decorate([
109
- (0, di_1.Injectable)(),
110
- (0, common_1.Scope)(common_1.ProviderScope.REQUEST)
155
+ (0, di_1.Injectable)()
111
156
  ], OidcInteractionContext);
112
157
  exports.OidcInteractionContext = OidcInteractionContext;
113
158
  //# sourceMappingURL=OidcInteractionContext.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"OidcInteractionContext.js","sourceRoot":"","sources":["../../../src/services/OidcInteractionContext.ts"],"names":[],"mappings":";;;;AAAA,yCAA6E;AAC7E,qCAA+B;AAC/B,iCAA4C;AAK5C,0CAAqC;AACrC,yDAAoD;AACpD,iDAA4C;AAI5C,IAAa,sBAAsB,GAAnC,MAAa,sBAAsB;IAejC,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,GAAG,CAAC,OAAc,CAAC;IACjC,CAAC;IAED,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC;IACzB,CAAC;IAED,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC;IACzB,CAAC;IAED,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;IACtB,CAAC;IAED,IAAI,OAAO;QACT,OAAQ,IAAI,CAAC,GAAW,CAAC,OAAO,CAAC;IACnC,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,OAAe,IAAI,CAAC,MAAM,CAAC,IAAI;QAClD,MAAM,OAAO,GAAG,IAAI,CAAC,gBAAgB,CAAC,qBAAqB,CAAC,IAAI,CAAC,CAAC;QAElE,IAAI,OAAO,EAAE;YACX,MAAM,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;SAC7B;IACH,CAAC;IAED,KAAK,CAAC,kBAAkB;QACtB,IAAI,CAAC,GAAG,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,GAAG,EAAE,CAAC,kBAAkB,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;QAE1G,OAAO,IAAI,CAAC,GAAG,CAAC;IAClB,CAAC;IAED,KAAK,CAAC,mBAAmB,CAAC,MAA0B,EAAE,UAA+C,EAAC,uBAAuB,EAAE,KAAK,EAAC;QACnI,OAAO,IAAI,CAAC,YAAY,CAAC,GAAG,EAAE,CA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AC;AAG7C;IADC,IAAA,WAAM,GAAE;sCACU,wBAAe;uDAAC;AAXxB,sBAAsB;IAFlC,IAAA,eAAU,GAAE;IACZ,IAAA,cAAK,EAAC,sBAAa,CAAC,OAAO,CAAC;GAChB,sBAAsB,CAkHlC;AAlHY,wDAAsB","sourcesContent":["import {Constant, PlatformContext, ProviderScope, Scope} from \"@tsed/common\";\nimport {Env} from \"@tsed/core\";\nimport {Inject, Injectable} from \"@tsed/di\";\nimport {Account, InteractionResults, PromptDetail, Provider} from \"oidc-provider\";\nimport {OidcSession} from \"../decorators/oidcSession\";\nimport {OidcClient} from \"../domain/interfaces\";\nimport {OidcInteraction} from \"../domain/OidcInteraction\";\nimport {debug} from \"../utils/debug\";\nimport {OidcInteractions} from \"./OidcInteractions\";\nimport {OidcProvider} from \"./OidcProvider\";\n\n@Injectable()\n@Scope(ProviderScope.REQUEST)\nexport class OidcInteractionContext {\n @Constant(\"env\")\n env: Env;\n\n @Inject()\n protected oidcProvider: OidcProvider;\n\n @Inject()\n protected oidcInteractions: OidcInteractions;\n\n @Inject()\n protected context: PlatformContext;\n\n protected raw: OidcInteraction;\n\n get session(): OidcSession | undefined {\n return this.raw.session as any;\n }\n\n get prompt(): PromptDetail {\n return this.raw.prompt;\n }\n\n get params(): Record<string, any> {\n return this.raw.params;\n }\n\n get uid(): string {\n return this.raw.uid;\n }\n\n get grantId(): string {\n return (this.raw as any).grantId;\n }\n\n async runInteraction(name: string = this.prompt.name) {\n const handler = this.oidcInteractions.getInteractionHandler(name);\n\n if (handler) {\n await handler(this.context);\n }\n }\n\n async interactionDetails(): Promise<OidcInteraction> {\n this.raw = await this.oidcProvider.get().interactionDetails(this.context.getReq(), this.context.getRes());\n\n return this.raw;\n }\n\n async interactionFinished(result: InteractionResults, options: {mergeWithLastSubmission?: boolean} = {mergeWithLastSubmission: false}) {\n return this.oidcProvider.get().interactionFinished(this.context.getReq(), this.context.getRes(), result, options);\n }\n\n async interactionResult(result: InteractionResults, options: {mergeWithLastSubmission?: boolean} = {mergeWithLastSubmission: false}) {\n return this.oidcProvider.get().interactionResult(this.context.getReq(), this.context.getRes(), result, options);\n }\n\n async render(view: string, result: any): Promise<string> {\n return this.context.response.render(view, result);\n }\n\n async save(ttl: number): Promise<string> {\n return this.raw.save(ttl);\n }\n\n async findClient(clientId: string = this.params.client_id): Promise<OidcClient | undefined> {\n return this.oidcProvider.get().Client.find(clientId);\n }\n\n async findAccount(sub?: string, token?: any): Promise<Account | undefined> {\n if (!sub && this.session) {\n sub = this.session?.accountId as any;\n }\n\n if (!sub) {\n return;\n }\n\n return this.oidcProvider.get().Account.findAccount(undefined as any, sub!, token);\n }\n\n async getGrant(): Promise<InstanceType<Provider[\"Grant\"]>> {\n const {Grant} = this.oidcProvider.get() as any;\n\n if (this.grantId) {\n // we'll be modifying existing grant in existing session\n // @ts-ignore\n return await (this.oidcProvider.get().find || Grant.find)(this.grantId);\n }\n\n return new Grant({\n accountId: this.session?.accountId,\n clientId: this.params.client_id\n });\n }\n\n debug(obj?: any): any {\n /* istanbul ignore next */\n if (this.env === Env.PROD) {\n return {session: undefined, dbg: {params: undefined, prompt: undefined}};\n }\n\n if (obj) {\n return debug(obj);\n }\n\n return {\n session: this.session ? this.debug(this.session) : undefined,\n dbg: {\n params: this.debug(this.params),\n prompt: this.debug(this.prompt)\n }\n };\n }\n}\n"]}
1
+ {"version":3,"file":"OidcInteractionContext.js","sourceRoot":"","sources":["../../../src/services/OidcInteractionContext.ts"],"names":[],"mappings":";;;;AAAA,yCAAsE;AACtE,qCAA+B;AAC/B,iCAA4C;AAC5C,iDAA8C;AAE9C,sDAQgC;AAGhC,6EAAwE;AAGxE,0CAAqC;AACrC,yDAAoD;AACpD,iDAA4C;AAG5C,IAAa,sBAAsB,GAAnC,MAAa,sBAAsB;IAEjC,GAAG,CAAM;IAGC,YAAY,CAAe;IAG3B,gBAAgB,CAAmB;IAGnC,IAAI,CAAkB;IAEhC,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,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C,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC;gBAC/B,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC;aAChC;SACF,CAAC;IACJ,CAAC;CACF,CAAA;AAhKC;IADC,IAAA,iBAAQ,EAAC,KAAK,CAAC;;mDACP;AAGT;IADC,IAAA,WAAM,GAAE;sCACe,2BAAY;4DAAC;AAGrC;IADC,IAAA,WAAM,GAAE;sCACmB,mCAAgB;gEAAC;AAG7C;IADC,IAAA,sBAAa,GAAE;sCACA,wBAAe;oDAAC;AAXrB,sBAAsB;IADlC,IAAA,eAAU,GAAE;GACA,sBAAsB,CAkKlC;AAlKY,wDAAsB","sourcesContent":["import {Constant, InjectContext, PlatformContext} from \"@tsed/common\";\nimport {Env} from \"@tsed/core\";\nimport {Inject, Injectable} from \"@tsed/di\";\nimport {Unauthorized} from \"@tsed/exceptions\";\nimport {Account, InteractionResults, PromptDetail, Provider} from \"oidc-provider\";\nimport {\n INTERACTION_CONTEXT,\n INTERACTION_DETAILS,\n INTERACTION_GRANT_ID,\n INTERACTION_PARAMS,\n INTERACTION_PROMPT,\n INTERACTION_SESSION,\n INTERACTION_UID\n} from \"../constants/constants\";\nimport {OidcSession} from \"../decorators/oidcSession\";\nimport {OidcClient} from \"../domain/interfaces\";\nimport {OidcBadInteractionName} from \"../domain/OidcBadInteractionName\";\nimport {OidcInteraction} from \"../domain/OidcInteraction\";\nimport {OidcInteractionPromptProps} from \"../domain/OidcInteractionPromptProps\";\nimport {debug} from \"../utils/debug\";\nimport {OidcInteractions} from \"./OidcInteractions\";\nimport {OidcProvider} from \"./OidcProvider\";\n\n@Injectable()\nexport class OidcInteractionContext {\n @Constant(\"env\")\n env: Env;\n\n @Inject()\n protected oidcProvider: OidcProvider;\n\n @Inject()\n protected oidcInteractions: OidcInteractions;\n\n @InjectContext()\n protected $ctx: PlatformContext;\n\n get raw(): OidcInteraction {\n return this.$ctx.get(INTERACTION_DETAILS)!;\n }\n\n get session(): OidcSession | undefined {\n return this.raw.session as any;\n }\n\n get prompt(): PromptDetail {\n return this.raw.prompt;\n }\n\n get params(): Record<string, any> {\n return this.raw.params;\n }\n\n get uid(): string {\n return this.raw.uid;\n }\n\n get grantId(): string {\n return (this.raw as any).grantId;\n }\n\n async runInteraction(name: string = this.prompt.name) {\n const handler = this.oidcInteractions.getInteractionHandler(name);\n\n if (handler) {\n await handler(this.$ctx);\n }\n }\n\n async interactionDetails(): Promise<OidcInteraction> {\n const raw = await this.oidcProvider.get().interactionDetails(this.$ctx.getReq(), this.$ctx.getRes());\n const {uid, prompt, params, session, grantId} = raw as any;\n\n this.$ctx.set(INTERACTION_CONTEXT, this);\n this.$ctx.set(INTERACTION_DETAILS, raw);\n this.$ctx.set(INTERACTION_UID, uid);\n this.$ctx.set(INTERACTION_PROMPT, prompt);\n this.$ctx.set(INTERACTION_PARAMS, params);\n this.$ctx.set(INTERACTION_GRANT_ID, grantId);\n this.$ctx.set(INTERACTION_SESSION, session);\n\n return raw;\n }\n\n async interactionFinished(result: InteractionResults, options: {mergeWithLastSubmission?: boolean} = {mergeWithLastSubmission: false}) {\n return this.oidcProvider.get().interactionFinished(this.$ctx.getReq(), this.$ctx.getRes(), result, options);\n }\n\n async interactionResult(result: InteractionResults, options: {mergeWithLastSubmission?: boolean} = {mergeWithLastSubmission: false}) {\n return this.oidcProvider.get().interactionResult(this.$ctx.getReq(), this.$ctx.getRes(), result, options);\n }\n\n async interactionPrompt(options: Record<string, any>): Promise<OidcInteractionPromptProps> {\n const client = await this.findClient();\n\n return {\n client,\n uid: this.uid,\n grantId: this.grantId,\n details: this.prompt.details,\n params: {\n ...this.params,\n ...options.params\n },\n ...options,\n ...this.debug()\n };\n }\n\n async render(view: string, result: any): Promise<string> {\n return this.$ctx.response.render(view, result);\n }\n\n async save(ttl: number): Promise<string> {\n return this.raw.save(ttl);\n }\n\n async findClient(clientId: string = this.params.client_id): Promise<OidcClient | undefined> {\n const key = `$client:${clientId}`;\n\n return this.$ctx.cacheAsync(key, () => this.oidcProvider.get().Client.find(clientId));\n }\n\n async findAccount(sub?: string, token?: any): Promise<Account | undefined> {\n if (!sub && this.session) {\n sub = this.session?.accountId as any;\n }\n\n if (!sub) {\n return;\n }\n\n const key = `$account:${sub}`;\n\n return this.$ctx.cacheAsync<Account | undefined>(key, (() => {\n return this.oidcProvider.get().Account.findAccount(undefined as any, sub!, token);\n }) as any);\n }\n\n async getGrant(): Promise<InstanceType<Provider[\"Grant\"]>> {\n const {Grant} = this.oidcProvider.get() as any;\n\n if (this.grantId) {\n // we'll be modifying existing grant in existing session\n // @ts-ignore\n return await (this.oidcProvider.get().find || Grant.find)(this.grantId);\n }\n\n return new Grant({\n accountId: this.session?.accountId,\n clientId: this.params.client_id\n });\n }\n\n checkInteractionName(name: string) {\n if (this.prompt.name !== name) {\n throw new OidcBadInteractionName(\"Bad interaction name\");\n }\n }\n\n async checkClientId(clientId = this.params.client_id) {\n const client = await this.findClient(clientId);\n\n if (!client) {\n throw new Unauthorized(`Unknown client_id ${clientId}`);\n }\n }\n\n debug(obj?: any): any {\n /* istanbul ignore next */\n if (this.env === Env.PROD) {\n return {session: undefined, dbg: {params: undefined, prompt: undefined}};\n }\n\n if (obj) {\n return debug(obj);\n }\n\n return {\n session: this.session ? this.debug(this.session) : undefined,\n dbg: {\n params: this.debug(this.params),\n prompt: this.debug(this.prompt)\n }\n };\n }\n}\n"]}
@@ -7,16 +7,16 @@ const core_1 = require("@tsed/core");
7
7
  const di_1 = require("@tsed/di");
8
8
  const constants_1 = require("../constants/constants");
9
9
  let OidcInteractions = class OidcInteractions {
10
- constructor() {
11
- this.interactions = new Map();
12
- }
10
+ injector;
11
+ env;
12
+ oidcSettings;
13
+ interactions = new Map();
13
14
  $onInit() {
14
15
  const platformHandler = this.injector.get(common_1.PlatformHandler);
15
16
  this.getInteractions().forEach((provider) => {
16
- var _a;
17
17
  const { name } = provider.store.get(constants_1.INTERACTION_OPTIONS);
18
18
  this.interactions.set(name, provider);
19
- if ((_a = this.injector.get(provider.token)) === null || _a === void 0 ? void 0 : _a.$prompt) {
19
+ if (this.injector.get(provider.token)?.$prompt) {
20
20
  provider.store.set("$prompt", platformHandler.createCustomHandler(provider, "$prompt"));
21
21
  }
22
22
  });
@@ -29,7 +29,7 @@ let OidcInteractions = class OidcInteractions {
29
29
  }
30
30
  return interactionsProvider.children
31
31
  .map((token) => this.injector.getProvider(token))
32
- .filter((provider) => (provider === null || provider === void 0 ? void 0 : provider.subType) === constants_1.INTERACTION);
32
+ .filter((provider) => provider?.subType === constants_1.INTERACTION);
33
33
  }
34
34
  getInteractionProvider(name) {
35
35
  return this.interactions.get(name);
@@ -37,9 +37,10 @@ let OidcInteractions = class OidcInteractions {
37
37
  getInteractionHandler(name) {
38
38
  const interaction = this.getInteractionProvider(name);
39
39
  if (interaction) {
40
+ const endpoint = common_1.EndpointMetadata.get(interaction.useClass, "$prompt");
40
41
  return (ctx) => {
41
42
  // Add current endpoint metadata to ctx
42
- ctx.endpoint = common_1.EndpointMetadata.get(interaction.useClass, "$prompt");
43
+ ctx.endpoint = endpoint;
43
44
  return interaction.store.get("$prompt")(ctx);
44
45
  };
45
46
  }
@@ -1 +1 @@
1
- {"version":3,"file":"OidcInteractions.js","sourceRoot":"","sources":["../../../src/services/OidcInteractions.ts"],"names":[],"mappings":";;;;AAAA,yCAAmH;AACnH,qCAA+B;AAC/B,iCAA6D;AAC7D,sDAAsF;AAKtF,IAAa,gBAAgB,GAA7B,MAAa,gBAAgB;IAA7B;QAUY,iBAAY,GAA0B,IAAI,GAAG,EAAE,CAAC;IA4C5D,CAAC;IA1CC,OAAO;QACL,MAAM,eAAe,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAkB,wBAAe,CAAE,CAAC;QAE7E,IAAI,CAAC,eAAe,EAAE,CAAC,OAAO,CAAC,CAAC,QAAkB,EAAE,EAAE;;YACpD,MAAM,EAAC,IAAI,EAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,GAA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AC,QAAQ,EAAE,SAAS,CAAC,CAAC;gBAErE,OAAO,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,CAAC;YAC/C,CAAC,CAAC;SACH;IACH,CAAC;CACF,CAAA;AApDC;IADC,IAAA,WAAM,GAAE;sCACC,oBAAe;kDAAC;AAG1B;IADC,IAAA,iBAAQ,EAAC,KAAK,CAAC;;6CACP;AAGT;IADC,IAAA,iBAAQ,EAAC,MAAM,CAAC;;sDACU;AARhB,gBAAgB;IAD5B,IAAA,eAAU,GAAE;GACA,gBAAgB,CAsD5B;AAtDY,4CAAgB","sourcesContent":["import {Constant, EndpointMetadata, PlatformContext, PlatformHandler, Provider, TokenProvider} from \"@tsed/common\";\nimport {Env} from \"@tsed/core\";\nimport {Inject, Injectable, InjectorService} from \"@tsed/di\";\nimport {INTERACTION, INTERACTION_OPTIONS, INTERACTIONS} from \"../constants/constants\";\nimport {OidcInteractionOptions} from \"../domain/OidcInteractionOptions\";\nimport {OidcSettings} from \"../domain/OidcSettings\";\n\n@Injectable()\nexport class OidcInteractions {\n @Inject()\n injector: InjectorService;\n\n @Constant(\"env\")\n env: Env;\n\n @Constant(\"oidc\")\n oidcSettings: OidcSettings;\n\n protected interactions: Map<string, Provider> = new Map();\n\n $onInit(): void {\n const platformHandler = this.injector.get<PlatformHandler>(PlatformHandler)!;\n\n this.getInteractions().forEach((provider: Provider) => {\n const {name} = provider.store.get<OidcInteractionOptions>(INTERACTION_OPTIONS);\n this.interactions.set(name, provider);\n\n if (this.injector.get(provider.token)?.$prompt) {\n provider.store.set(\"$prompt\", platformHandler.createCustomHandler(provider, \"$prompt\"));\n }\n });\n }\n\n getInteractions(): Provider[] {\n const interactionsProvider = this.injector.getProviders().find((provider) => provider.subType === INTERACTIONS);\n\n /* istanbul ignore next */\n if (!interactionsProvider) {\n return [];\n }\n\n return interactionsProvider.children\n .map((token: TokenProvider) => this.injector.getProvider(token)!)\n .filter((provider: Provider) => provider?.subType === INTERACTION);\n }\n\n getInteractionProvider(name: string): Provider | undefined {\n return this.interactions.get(name);\n }\n\n getInteractionHandler(name: string) {\n const interaction = this.getInteractionProvider(name);\n\n if (interaction) {\n return (ctx: PlatformContext) => {\n // Add current endpoint metadata to ctx\n ctx.endpoint = EndpointMetadata.get(interaction.useClass, \"$prompt\");\n\n return interaction.store.get(\"$prompt\")(ctx);\n };\n }\n }\n}\n"]}
1
+ {"version":3,"file":"OidcInteractions.js","sourceRoot":"","sources":["../../../src/services/OidcInteractions.ts"],"names":[],"mappings":";;;;AAAA,yCAAmH;AACnH,qCAA+B;AAC/B,iCAA6D;AAC7D,sDAAsF;AAKtF,IAAa,gBAAgB,GAA7B,MAAa,gBAAgB;IAE3B,QAAQ,CAAkB;IAG1B,GAAG,CAAM;IAGT,YAAY,CAAe;IAEjB,YAAY,GAA0B,IAAI,GAAG,EAAE,CAAC;IAE1D,OAAO;QACL,MAAM,eAAe,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAkB,wBAAe,CAAE,CAAC;QAE7E,IAAI,CAAC,eAAe,EAAE,CAAC,OAAO,CAAC,CAAC,QAAkB,EAAE,EAAE;YACpD,MAAM,EAAC,IAAI,EAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAyB,+BAAmB,CAAC,CAAC;YAC/E,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;YAEtC,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,EAAE;gBAC9C,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,SAAS,EAAE,eAAe,CAAC,mBAAmB,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAC;aACzF;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IAED,eAAe;QACb,MAAM,oBAAoB,GAAG,IAAI,CAAC,QAAQ,CAAC,YAAY,EAAE,CAAC,IA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, TokenProvider} from \"@tsed/common\";\nimport {Env} from \"@tsed/core\";\nimport {Inject, Injectable, InjectorService} from \"@tsed/di\";\nimport {INTERACTION, INTERACTION_OPTIONS, INTERACTIONS} from \"../constants/constants\";\nimport {OidcInteractionOptions} from \"../domain/OidcInteractionOptions\";\nimport {OidcSettings} from \"../domain/OidcSettings\";\n\n@Injectable()\nexport class OidcInteractions {\n @Inject()\n injector: InjectorService;\n\n @Constant(\"env\")\n env: Env;\n\n @Constant(\"oidc\")\n oidcSettings: OidcSettings;\n\n protected interactions: Map<string, Provider> = new Map();\n\n $onInit(): void {\n const platformHandler = this.injector.get<PlatformHandler>(PlatformHandler)!;\n\n this.getInteractions().forEach((provider: Provider) => {\n const {name} = provider.store.get<OidcInteractionOptions>(INTERACTION_OPTIONS);\n this.interactions.set(name, provider);\n\n if (this.injector.get(provider.token)?.$prompt) {\n provider.store.set(\"$prompt\", platformHandler.createCustomHandler(provider, \"$prompt\"));\n }\n });\n }\n\n getInteractions(): Provider[] {\n const interactionsProvider = this.injector.getProviders().find((provider) => provider.subType === INTERACTIONS);\n\n /* istanbul ignore next */\n if (!interactionsProvider) {\n return [];\n }\n\n return interactionsProvider.children\n .map((token: TokenProvider) => this.injector.getProvider(token)!)\n .filter((provider: Provider) => provider?.subType === INTERACTION);\n }\n\n getInteractionProvider(name: string): Provider | undefined {\n return this.interactions.get(name);\n }\n\n getInteractionHandler(name: string) {\n const interaction = this.getInteractionProvider(name);\n\n if (interaction) {\n const endpoint = EndpointMetadata.get(interaction.useClass, \"$prompt\");\n return (ctx: PlatformContext) => {\n // Add current endpoint metadata to ctx\n ctx.endpoint = endpoint;\n return interaction.store.get(\"$prompt\")(ctx);\n };\n }\n }\n}\n"]}
@@ -6,6 +6,9 @@ const di_1 = require("@tsed/di");
6
6
  const path_1 = require("path");
7
7
  const jwks_1 = require("@tsed/jwks");
8
8
  let OidcJwks = class OidcJwks {
9
+ jwksPath;
10
+ certificates;
11
+ keys;
9
12
  async $onInit() {
10
13
  return this.getJwks();
11
14
  }
@@ -1 +1 @@
1
- {"version":3,"file":"OidcJwks.js","sourceRoot":"","sources":["../../../src/services/OidcJwks.ts"],"names":[],"mappings":";;;;AAAA,iCAA8C;AAC9C,+BAA0B;AAC1B,qCAAsD;AAGtD,IAAa,QAAQ,GAArB,MAAa,QAAQ;IASnB,KAAK,CAAC,OAAO;QACX,OAAO,IAAI,CAAC,OAAO,EAAE,CAAC;IACxB,CAAC;IAED,OAAO;QACL,OAAO,IAAA,cAAO,EAAC;YACb,IAAI,EAAE,IAAI,CAAC,QAAQ;YACnB,YAAY,EAAE,IAAI,CAAC,YAAY;SAChC,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AAjBC;IADC,IAAA,aAAQ,EAAC,eAAe,EAAE,IAAA,WAAI,EAAC,OAAO,CAAC,GAAG,EAAE,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;;0CACnD;AAGjB;IADC,IAAA,aAAQ,EAAC,mBAAmB,CAAC;;8CACK;AALxB,QAAQ;IADpB,IAAA,eAAU,GAAE;GACA,QAAQ,CAmBpB;AAnBY,4BAAQ","sourcesContent":["import {Constant, Injectable} from \"@tsed/di\";\nimport {join} from \"path\";\nimport {getJwks, JwksKeyParameters} from \"@tsed/jwks\";\n\n@Injectable()\nexport class OidcJwks {\n @Constant(\"oidc.jwksPath\", join(process.cwd(), \"keys\", \"jwks.json\"))\n jwksPath: string;\n\n @Constant(\"oidc.certificates\")\n certificates?: JwksKeyParameters[];\n\n keys: string;\n\n async $onInit() {\n return this.getJwks();\n }\n\n getJwks() {\n return getJwks({\n path: this.jwksPath,\n certificates: this.certificates\n });\n }\n}\n"]}
1
+ {"version":3,"file":"OidcJwks.js","sourceRoot":"","sources":["../../../src/services/OidcJwks.ts"],"names":[],"mappings":";;;;AAAA,iCAA8C;AAC9C,+BAA0B;AAC1B,qCAAsD;AAGtD,IAAa,QAAQ,GAArB,MAAa,QAAQ;IAEnB,QAAQ,CAAS;IAGjB,YAAY,CAAuB;IAEnC,IAAI,CAAS;IAEb,KAAK,CAAC,OAAO;QACX,OAAO,IAAI,CAAC,OAAO,EAAE,CAAC;IACxB,CAAC;IAED,OAAO;QACL,OAAO,IAAA,cAAO,EAAC;YACb,IAAI,EAAE,IAAI,CAAC,QAAQ;YACnB,YAAY,EAAE,IAAI,CAAC,YAAY;SAChC,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AAjBC;IADC,IAAA,aAAQ,EAAC,eAAe,EAAE,IAAA,WAAI,EAAC,OAAO,CAAC,GAAG,EAAE,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;;0CACnD;AAGjB;IADC,IAAA,aAAQ,EAAC,mBAAmB,CAAC;;8CACK;AALxB,QAAQ;IADpB,IAAA,eAAU,GAAE;GACA,QAAQ,CAmBpB;AAnBY,4BAAQ","sourcesContent":["import {Constant, Injectable} from \"@tsed/di\";\nimport {join} from \"path\";\nimport {getJwks, JwksKeyParameters} from \"@tsed/jwks\";\n\n@Injectable()\nexport class OidcJwks {\n @Constant(\"oidc.jwksPath\", join(process.cwd(), \"keys\", \"jwks.json\"))\n jwksPath: string;\n\n @Constant(\"oidc.certificates\")\n certificates?: JwksKeyParameters[];\n\n keys: string;\n\n async $onInit() {\n return this.getJwks();\n }\n\n getJwks() {\n return getJwks({\n path: this.jwksPath,\n certificates: this.certificates\n });\n }\n}\n"]}
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.OidcProvider = void 0;
4
4
  const tslib_1 = require("tslib");
5
+ const common_1 = require("@tsed/common");
5
6
  const core_1 = require("@tsed/core");
6
7
  const di_1 = require("@tsed/di");
7
8
  const oidc_provider_1 = require("oidc-provider");
@@ -9,14 +10,25 @@ const constants_1 = require("../constants/constants");
9
10
  const OidcAdapters_1 = require("./OidcAdapters");
10
11
  const OidcInteractions_1 = require("./OidcInteractions");
11
12
  const OidcJwks_1 = require("./OidcJwks");
12
- const common_1 = require("@tsed/common");
13
13
  let OidcProvider = class OidcProvider {
14
+ raw;
15
+ env;
16
+ httpPort;
17
+ httpsPort;
18
+ issuer;
19
+ oidc;
20
+ platformName;
21
+ oidcJwks;
22
+ oidcInteractions;
23
+ adapters;
24
+ injector;
25
+ app;
14
26
  hasConfiguration() {
15
27
  return !!this.oidc;
16
28
  }
17
29
  async getConfiguration() {
18
30
  const [jwks, adapter] = await Promise.all([this.oidcJwks.getJwks(), this.adapters.createAdapterClass()]);
19
- const { issuer, jwksPath, secureKey, proxy, Accounts, ...options } = this.oidc;
31
+ const { issuer, jwksPath, secureKey, proxy, Accounts, secureCookies = this.env == core_1.Env.PROD, ...options } = this.oidc;
20
32
  const configuration = {
21
33
  interactions: {
22
34
  /* istanbul ignore next */
@@ -27,9 +39,9 @@ let OidcProvider = class OidcProvider {
27
39
  jwks
28
40
  };
29
41
  if (Accounts) {
30
- configuration.findAccount = (ctx, id, token) => this.injector.get(Accounts).findAccount(id, token, ctx.req.$ctx);
42
+ configuration.findAccount = (ctx, id, token) => this.injector.get(Accounts).findAccount(id, token);
31
43
  }
32
- if (this.env === core_1.Env.PROD) {
44
+ if (secureCookies) {
33
45
  (0, core_1.setValue)(configuration, "cookies.short.secure", true);
34
46
  (0, core_1.setValue)(configuration, "cookies.long.secure", true);
35
47
  }
@@ -60,10 +72,10 @@ let OidcProvider = class OidcProvider {
60
72
  * Create a new instance of OidcProvider
61
73
  */
62
74
  async create() {
63
- const { proxy, secureKey } = this.oidc;
75
+ const { proxy = this.env === core_1.Env.PROD, secureKey, allowHttpLocalhost = this.env !== core_1.Env.PROD } = this.oidc;
64
76
  const configuration = await this.getConfiguration();
65
77
  const oidcProvider = new oidc_provider_1.Provider(this.getIssuer(), configuration);
66
- if (proxy || this.env === core_1.Env.PROD) {
78
+ if (proxy) {
67
79
  // istanbul ignore next
68
80
  switch (this.platformName) {
69
81
  default:
@@ -79,7 +91,7 @@ let OidcProvider = class OidcProvider {
79
91
  oidcProvider.app.keys = secureKey;
80
92
  }
81
93
  this.raw = oidcProvider;
82
- if (this.env !== core_1.Env.PROD) {
94
+ if (allowHttpLocalhost) {
83
95
  this.allowHttpLocalhost();
84
96
  }
85
97
  await this.injector.emit("$onCreateOIDC", this.raw);