@tsed/oidc-provider 7.0.0-beta.13 → 7.0.0-beta.16

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 (29) hide show
  1. package/lib/cjs/domain/OidcBadInteractionName.js +8 -0
  2. package/lib/cjs/domain/OidcBadInteractionName.js.map +1 -0
  3. package/lib/cjs/domain/OidcInteractionPromptProps.js +3 -0
  4. package/lib/cjs/domain/OidcInteractionPromptProps.js.map +1 -0
  5. package/lib/cjs/index.js +2 -0
  6. package/lib/cjs/index.js.map +1 -1
  7. package/lib/cjs/middlewares/OidcInteractionMiddleware.js.map +1 -1
  8. package/lib/cjs/services/OidcInteractionContext.js +40 -8
  9. package/lib/cjs/services/OidcInteractionContext.js.map +1 -1
  10. package/lib/cjs/services/OidcInteractions.js +2 -1
  11. package/lib/cjs/services/OidcInteractions.js.map +1 -1
  12. package/lib/esm/domain/OidcBadInteractionName.js +4 -0
  13. package/lib/esm/domain/OidcBadInteractionName.js.map +1 -0
  14. package/lib/esm/domain/OidcInteractionPromptProps.js +2 -0
  15. package/lib/esm/domain/OidcInteractionPromptProps.js.map +1 -0
  16. package/lib/esm/index.js +2 -0
  17. package/lib/esm/index.js.map +1 -1
  18. package/lib/esm/middlewares/OidcInteractionMiddleware.js +1 -1
  19. package/lib/esm/middlewares/OidcInteractionMiddleware.js.map +1 -1
  20. package/lib/esm/services/OidcInteractionContext.js +40 -8
  21. package/lib/esm/services/OidcInteractionContext.js.map +1 -1
  22. package/lib/esm/services/OidcInteractions.js +2 -1
  23. package/lib/esm/services/OidcInteractions.js.map +1 -1
  24. package/lib/types/domain/OidcBadInteractionName.d.ts +3 -0
  25. package/lib/types/domain/OidcInteractionPromptProps.d.ts +9 -0
  26. package/lib/types/index.d.ts +2 -0
  27. package/lib/types/services/OidcInteractionContext.d.ts +5 -1
  28. package/package.json +7 -7
  29. package/readme.md +1 -1
@@ -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"]}
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"]}
@@ -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;IAE1B,gBAAgB,CAAmB;IAGnC,QAAQ,CAAkB;IAEpC,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,yCAA0E;AAC1E,sDAQgC;AAChC,+EAA0E;AAC1E,mEAA8D;AAG9D,IAAa,yBAAyB,GAAtC,MAAa,yBAAyB;IAE1B,gBAAgB,CAAmB;IAGnC,QAAQ,CAAkB;IAEpC,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_GRANT_ID,\n INTERACTION_PARAMS,\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"]}
@@ -5,6 +5,8 @@ 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 OidcBadInteractionName_1 = require("../domain/OidcBadInteractionName");
8
10
  const debug_1 = require("../utils/debug");
9
11
  const OidcInteractions_1 = require("./OidcInteractions");
10
12
  const OidcProvider_1 = require("./OidcProvider");
@@ -12,7 +14,7 @@ let OidcInteractionContext = class OidcInteractionContext {
12
14
  env;
13
15
  oidcProvider;
14
16
  oidcInteractions;
15
- context;
17
+ $ctx;
16
18
  raw;
17
19
  get session() {
18
20
  return this.raw.session;
@@ -32,27 +34,46 @@ let OidcInteractionContext = class OidcInteractionContext {
32
34
  async runInteraction(name = this.prompt.name) {
33
35
  const handler = this.oidcInteractions.getInteractionHandler(name);
34
36
  if (handler) {
35
- await handler(this.context);
37
+ await handler(this.$ctx);
36
38
  }
37
39
  }
38
40
  async interactionDetails() {
39
- this.raw = await this.oidcProvider.get().interactionDetails(this.context.getReq(), this.context.getRes());
41
+ this.raw = await this.oidcProvider.get().interactionDetails(this.$ctx.getReq(), this.$ctx.getRes());
40
42
  return this.raw;
41
43
  }
42
44
  async interactionFinished(result, options = { mergeWithLastSubmission: false }) {
43
- return this.oidcProvider.get().interactionFinished(this.context.getReq(), this.context.getRes(), result, options);
45
+ return this.oidcProvider.get().interactionFinished(this.$ctx.getReq(), this.$ctx.getRes(), result, options);
44
46
  }
45
47
  async interactionResult(result, options = { mergeWithLastSubmission: false }) {
46
- return this.oidcProvider.get().interactionResult(this.context.getReq(), this.context.getRes(), result, options);
48
+ return this.oidcProvider.get().interactionResult(this.$ctx.getReq(), this.$ctx.getRes(), result, options);
49
+ }
50
+ async interactionPrompt(options) {
51
+ const client = await this.findClient();
52
+ return {
53
+ client,
54
+ uid: this.uid,
55
+ grantId: this.grantId,
56
+ details: this.prompt.details,
57
+ params: {
58
+ ...this.params,
59
+ ...options.params
60
+ },
61
+ ...options,
62
+ ...this.debug()
63
+ };
47
64
  }
48
65
  async render(view, result) {
49
- return this.context.response.render(view, result);
66
+ return this.$ctx.response.render(view, result);
50
67
  }
51
68
  async save(ttl) {
52
69
  return this.raw.save(ttl);
53
70
  }
54
71
  async findClient(clientId = this.params.client_id) {
55
- return this.oidcProvider.get().Client.find(clientId);
72
+ const key = `$client:${clientId}`;
73
+ if (!this.$ctx.has(key)) {
74
+ this.$ctx.set(key, await this.oidcProvider.get().Client.find(clientId));
75
+ }
76
+ return this.$ctx.get(key);
56
77
  }
57
78
  async findAccount(sub, token) {
58
79
  if (!sub && this.session) {
@@ -75,6 +96,17 @@ let OidcInteractionContext = class OidcInteractionContext {
75
96
  clientId: this.params.client_id
76
97
  });
77
98
  }
99
+ checkInteractionName(name) {
100
+ if (this.prompt.name !== name) {
101
+ throw new OidcBadInteractionName_1.OidcBadInteractionName("Bad interaction name");
102
+ }
103
+ }
104
+ async checkClientId(clientId = this.params.client_id) {
105
+ const client = await this.findClient(clientId);
106
+ if (!client) {
107
+ throw new exceptions_1.Unauthorized(`Unknown client_id ${clientId}`);
108
+ }
109
+ }
78
110
  debug(obj) {
79
111
  /* istanbul ignore next */
80
112
  if (this.env === core_1.Env.PROD) {
@@ -107,7 +139,7 @@ tslib_1.__decorate([
107
139
  tslib_1.__decorate([
108
140
  (0, di_1.Inject)(),
109
141
  tslib_1.__metadata("design:type", common_1.PlatformContext)
110
- ], OidcInteractionContext.prototype, "context", void 0);
142
+ ], OidcInteractionContext.prototype, "$ctx", void 0);
111
143
  OidcInteractionContext = tslib_1.__decorate([
112
144
  (0, di_1.Injectable)(),
113
145
  (0, common_1.Scope)(common_1.ProviderScope.REQUEST)
@@ -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,GAAG,CAAM;IAGC,YAAY,CAAe;IAG3B,gBAAgB,CAAmB;IAGnC,OAAO,CAAkB;IAEzB,GAAG,CAAkB;IAE/B,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,GA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AAC,IAAI,CAAC,MAAM,CAAC;gBAC/B,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC;aAChC;SACF,CAAC;IACJ,CAAC;CACF,CAAA;AAhHC;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,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,yCAA6E;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GAChB,sBAAsB,CAsJlC;AAtJY,wDAAsB","sourcesContent":["import {Constant, PlatformContext, ProviderScope, Scope} 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 {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()\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 $ctx: 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.$ctx);\n }\n }\n\n async interactionDetails(): Promise<OidcInteraction> {\n this.raw = await this.oidcProvider.get().interactionDetails(this.$ctx.getReq(), this.$ctx.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.$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 if (!this.$ctx.has(key)) {\n this.$ctx.set(key, await this.oidcProvider.get().Client.find(clientId));\n }\n\n return this.$ctx.get(key);\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 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"]}
@@ -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;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,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AsD5B;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,q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AK,uBAAW,CAAC,CAAC;IACvE,CAAC;IAED,sBAAsB,CAAC,IAAY;QACjC,OAAO,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACrC,CAAC;IAED,qBAAqB,CAAC,IAAY;QAChC,MAAM,WAAW,GAAG,IAAI,CAAC,sBAAsB,CAAC,IAAI,CAAC,CAAC;QAEtD,IAAI,WAAW,EAAE;YACf,MAAM,QAAQ,GAAG,yBAAgB,CAAC,GAAG,CAAC,WAAW,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;YACvE,OAAO,CAAC,GAAoB,EAAE,EAAE;gBAC9B,uCAAuC;gBACvC,GAAG,CAAC,QAAQ,GAAG,QAAQ,CAAC;gBACxB,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 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"]}
@@ -0,0 +1,4 @@
1
+ import { BadRequest } from "@tsed/exceptions";
2
+ export class OidcBadInteractionName extends BadRequest {
3
+ }
4
+ //# sourceMappingURL=OidcBadInteractionName.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OidcBadInteractionName.js","sourceRoot":"","sources":["../../../src/domain/OidcBadInteractionName.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,kBAAkB,CAAC;AAE5C,MAAM,OAAO,sBAAuB,SAAQ,UAAU;CAAG","sourcesContent":["import {BadRequest} from \"@tsed/exceptions\";\n\nexport class OidcBadInteractionName extends BadRequest {}\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# 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"]}
package/lib/esm/index.js CHANGED
@@ -13,9 +13,11 @@ export * from "./decorators/params.js";
13
13
  export * from "./decorators/prompt.js";
14
14
  export * from "./decorators/uid.js";
15
15
  export * from "./domain/OidcAccountsMethods.js";
16
+ export * from "./domain/OidcBadInteractionName.js";
16
17
  export * from "./domain/OidcInteraction.js";
17
18
  export * from "./domain/OidcInteractionMethods.js";
18
19
  export * from "./domain/OidcInteractionOptions.js";
20
+ export * from "./domain/OidcInteractionPromptProps.js";
19
21
  export * from "./domain/OidcSettings.js";
20
22
  export * from "./domain/interfaces.js";
21
23
  export * from "./middlewares/OidcInteractionMiddleware.js";
@@ -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,8BAA8B,CAAC;AAC7C,cAAc,0BAA0B,CAAC;AACzC,cAAc,iCAAiC,CAAC;AAChD,cAAc,iCAAiC,CAAC;AAChD,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/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,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,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/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,6 +1,6 @@
1
1
  import { __decorate, __metadata, __param } from "tslib";
2
2
  import { Context, Inject, InjectorService, Middleware } from "@tsed/common";
3
- import { INTERACTION_CONTEXT, INTERACTION_DETAILS, INTERACTION_PARAMS, INTERACTION_GRANT_ID, INTERACTION_PROMPT, INTERACTION_SESSION, INTERACTION_UID } from "../constants/constants.js";
3
+ import { INTERACTION_CONTEXT, INTERACTION_DETAILS, INTERACTION_GRANT_ID, INTERACTION_PARAMS, INTERACTION_PROMPT, INTERACTION_SESSION, INTERACTION_UID } from "../constants/constants.js";
4
4
  import { OidcInteractionContext } from "../services/OidcInteractionContext.js";
5
5
  import { OidcInteractions } from "../services/OidcInteractions.js";
6
6
  let OidcInteractionMiddleware = class OidcInteractionMiddleware {
@@ -1 +1 @@
1
- {"version":3,"file":"OidcInteractionMiddleware.js","sourceRoot":"","sources":["../../../src/middlewares/OidcInteractionMiddleware.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,UAAU,EAAC,MAAM,cAAc,CAAC;AAC1E,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,kBAAkB,EAClB,oBAAoB,EACpB,kBAAkB,EAClB,mBAAmB,EACnB,eAAe,EAChB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAC,sBAAsB,EAAC,MAAM,oCAAoC,CAAC;AAC1E,OAAO,EAAC,gBAAgB,EAAC,MAAM,8BAA8B,CAAC;AAG9D,IAAa,yBAAyB,GAAtC,MAAa,yBAAyB;IAE1B,gBAAgB,CAAmB;IAGnC,QAAQ,CAAkB;IAEpC,KAAK,CAAC,GAAG,CAAY,OAAgB;QACnC,MAAM,eAAe,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAyB,sBAAsB,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,mBAAmB,EAAE,eAAe,CAAC,CAAC;QAClD,OAAO,CAAC,GAAG,CAAC,mBAAmB,EAAE,kBAAkB,CAAC,CAAC;QACrD,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,GAAG,CAAC,CAAC;QAClC,OAAO,CAAC,GAAG,CAAC,kBAAkB,EAAE,MAAM,CAAC,CAAC;QACxC,OAAO,CAAC,GAAG,CAAC,kBAAkB,EAAE,MAAM,CAAC,CAAC;QACxC,OAAO,CAAC,GAAG,CAAC,oBAAoB,EAAE,OAAO,CAAC,CAAC;QAC3C,OAAO,CAAC,GAAG,CAAC,mBAAmB,EAAE,OAAO,CAAC,CAAC;IAC5C,CAAC;CACF,CAAA;AAlBC;IADC,MAAM,EAAE;8BACmB,gBAAgB;mEAAC;AAG7C;IADC,MAAM,EAAE;8BACW,eAAe;2DAAC;AAEpC;IAAW,WAAA,OAAO,EAAE,CAAA;;;;oDAYnB;AAnBU,yBAAyB;IADrC,UAAU,EAAE;GACA,yBAAyB,CAoBrC;SApBY,yBAAyB","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,OAAO,EAAC,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,UAAU,EAAC,MAAM,cAAc,CAAC;AAC1E,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,EACpB,kBAAkB,EAClB,kBAAkB,EAClB,mBAAmB,EACnB,eAAe,EAChB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAC,sBAAsB,EAAC,MAAM,oCAAoC,CAAC;AAC1E,OAAO,EAAC,gBAAgB,EAAC,MAAM,8BAA8B,CAAC;AAG9D,IAAa,yBAAyB,GAAtC,MAAa,yBAAyB;IAE1B,gBAAgB,CAAmB;IAGnC,QAAQ,CAAkB;IAEpC,KAAK,CAAC,GAAG,CAAY,OAAgB;QACnC,MAAM,eAAe,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAyB,sBAAsB,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,mBAAmB,EAAE,eAAe,CAAC,CAAC;QAClD,OAAO,CAAC,GAAG,CAAC,mBAAmB,EAAE,kBAAkB,CAAC,CAAC;QACrD,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,GAAG,CAAC,CAAC;QAClC,OAAO,CAAC,GAAG,CAAC,kBAAkB,EAAE,MAAM,CAAC,CAAC;QACxC,OAAO,CAAC,GAAG,CAAC,kBAAkB,EAAE,MAAM,CAAC,CAAC;QACxC,OAAO,CAAC,GAAG,CAAC,oBAAoB,EAAE,OAAO,CAAC,CAAC;QAC3C,OAAO,CAAC,GAAG,CAAC,mBAAmB,EAAE,OAAO,CAAC,CAAC;IAC5C,CAAC;CACF,CAAA;AAlBC;IADC,MAAM,EAAE;8BACmB,gBAAgB;mEAAC;AAG7C;IADC,MAAM,EAAE;8BACW,eAAe;2DAAC;AAEpC;IAAW,WAAA,OAAO,EAAE,CAAA;;;;oDAYnB;AAnBU,yBAAyB;IADrC,UAAU,EAAE;GACA,yBAAyB,CAoBrC;SApBY,yBAAyB","sourcesContent":["import {Context, Inject, InjectorService, Middleware} from \"@tsed/common\";\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 {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"]}
@@ -2,6 +2,8 @@ import { __decorate, __metadata } from "tslib";
2
2
  import { Constant, PlatformContext, ProviderScope, Scope } from "@tsed/common";
3
3
  import { Env } from "@tsed/core";
4
4
  import { Inject, Injectable } from "@tsed/di";
5
+ import { Unauthorized } from "@tsed/exceptions";
6
+ import { OidcBadInteractionName } from "../domain/OidcBadInteractionName.js";
5
7
  import { debug } from "../utils/debug.js";
6
8
  import { OidcInteractions } from "./OidcInteractions.js";
7
9
  import { OidcProvider } from "./OidcProvider.js";
@@ -9,7 +11,7 @@ let OidcInteractionContext = class OidcInteractionContext {
9
11
  env;
10
12
  oidcProvider;
11
13
  oidcInteractions;
12
- context;
14
+ $ctx;
13
15
  raw;
14
16
  get session() {
15
17
  return this.raw.session;
@@ -29,27 +31,46 @@ let OidcInteractionContext = class OidcInteractionContext {
29
31
  async runInteraction(name = this.prompt.name) {
30
32
  const handler = this.oidcInteractions.getInteractionHandler(name);
31
33
  if (handler) {
32
- await handler(this.context);
34
+ await handler(this.$ctx);
33
35
  }
34
36
  }
35
37
  async interactionDetails() {
36
- this.raw = await this.oidcProvider.get().interactionDetails(this.context.getReq(), this.context.getRes());
38
+ this.raw = await this.oidcProvider.get().interactionDetails(this.$ctx.getReq(), this.$ctx.getRes());
37
39
  return this.raw;
38
40
  }
39
41
  async interactionFinished(result, options = { mergeWithLastSubmission: false }) {
40
- return this.oidcProvider.get().interactionFinished(this.context.getReq(), this.context.getRes(), result, options);
42
+ return this.oidcProvider.get().interactionFinished(this.$ctx.getReq(), this.$ctx.getRes(), result, options);
41
43
  }
42
44
  async interactionResult(result, options = { mergeWithLastSubmission: false }) {
43
- return this.oidcProvider.get().interactionResult(this.context.getReq(), this.context.getRes(), result, options);
45
+ return this.oidcProvider.get().interactionResult(this.$ctx.getReq(), this.$ctx.getRes(), result, options);
46
+ }
47
+ async interactionPrompt(options) {
48
+ const client = await this.findClient();
49
+ return {
50
+ client,
51
+ uid: this.uid,
52
+ grantId: this.grantId,
53
+ details: this.prompt.details,
54
+ params: {
55
+ ...this.params,
56
+ ...options.params
57
+ },
58
+ ...options,
59
+ ...this.debug()
60
+ };
44
61
  }
45
62
  async render(view, result) {
46
- return this.context.response.render(view, result);
63
+ return this.$ctx.response.render(view, result);
47
64
  }
48
65
  async save(ttl) {
49
66
  return this.raw.save(ttl);
50
67
  }
51
68
  async findClient(clientId = this.params.client_id) {
52
- return this.oidcProvider.get().Client.find(clientId);
69
+ const key = `$client:${clientId}`;
70
+ if (!this.$ctx.has(key)) {
71
+ this.$ctx.set(key, await this.oidcProvider.get().Client.find(clientId));
72
+ }
73
+ return this.$ctx.get(key);
53
74
  }
54
75
  async findAccount(sub, token) {
55
76
  if (!sub && this.session) {
@@ -72,6 +93,17 @@ let OidcInteractionContext = class OidcInteractionContext {
72
93
  clientId: this.params.client_id
73
94
  });
74
95
  }
96
+ checkInteractionName(name) {
97
+ if (this.prompt.name !== name) {
98
+ throw new OidcBadInteractionName("Bad interaction name");
99
+ }
100
+ }
101
+ async checkClientId(clientId = this.params.client_id) {
102
+ const client = await this.findClient(clientId);
103
+ if (!client) {
104
+ throw new Unauthorized(`Unknown client_id ${clientId}`);
105
+ }
106
+ }
75
107
  debug(obj) {
76
108
  /* istanbul ignore next */
77
109
  if (this.env === Env.PROD) {
@@ -104,7 +136,7 @@ __decorate([
104
136
  __decorate([
105
137
  Inject(),
106
138
  __metadata("design:type", PlatformContext)
107
- ], OidcInteractionContext.prototype, "context", void 0);
139
+ ], OidcInteractionContext.prototype, "$ctx", void 0);
108
140
  OidcInteractionContext = __decorate([
109
141
  Injectable(),
110
142
  Scope(ProviderScope.REQUEST)
@@ -1 +1 @@
1
- {"version":3,"file":"OidcInteractionContext.js","sourceRoot":"","sources":["../../../src/services/OidcInteractionContext.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,QAAQ,EAAE,eAAe,EAAE,aAAa,EAAE,KAAK,EAAC,MAAM,cAAc,CAAC;AAC7E,OAAO,EAAC,GAAG,EAAC,MAAM,YAAY,CAAC;AAC/B,OAAO,EAAC,MAAM,EAAE,UAAU,EAAC,MAAM,UAAU,CAAC;AAK5C,OAAO,EAAC,KAAK,EAAC,MAAM,gBAA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AC;AAG7C;IADC,MAAM,EAAE;8BACU,eAAe;uDAAC;AAXxB,sBAAsB;IAFlC,UAAU,EAAE;IACZ,KAAK,CAAC,aAAa,CAAC,OAAO,CAAC;GAChB,sBAAsB,CAkHlC;SAlHY,sBAAsB","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,OAAO,EAAC,QAAQ,EAAE,eAAe,EAAE,aAAa,EAAE,KAAK,EAAC,MAAM,cAAc,CAAC;AAC7E,OAAO,EAAC,GAAG,EAAC,MAAM,YAAY,CAAC;AAC/B,OAAO,EAAC,MAAM,EAAE,UAAU,EAAC,MAAM,UAAU,CAAC;AAC5C,OAAO,EAAC,YAAY,EAAC,MAAM,kBAAkB,CAAC;AAI9C,OAAO,EAAC,sBAAsB,EAAC,MAAM,kCAAkC,CAAC;AAGxE,OAAO,EAAC,KAAK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AtJY,sBAAsB","sourcesContent":["import {Constant, PlatformContext, ProviderScope, Scope} 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 {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()\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 $ctx: 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.$ctx);\n }\n }\n\n async interactionDetails(): Promise<OidcInteraction> {\n this.raw = await this.oidcProvider.get().interactionDetails(this.$ctx.getReq(), this.$ctx.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.$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 if (!this.$ctx.has(key)) {\n this.$ctx.set(key, await this.oidcProvider.get().Client.find(clientId));\n }\n\n return this.$ctx.get(key);\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 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"]}
@@ -34,9 +34,10 @@ let OidcInteractions = class OidcInteractions {
34
34
  getInteractionHandler(name) {
35
35
  const interaction = this.getInteractionProvider(name);
36
36
  if (interaction) {
37
+ const endpoint = EndpointMetadata.get(interaction.useClass, "$prompt");
37
38
  return (ctx) => {
38
39
  // Add current endpoint metadata to ctx
39
- ctx.endpoint = EndpointMetadata.get(interaction.useClass, "$prompt");
40
+ ctx.endpoint = endpoint;
40
41
  return interaction.store.get("$prompt")(ctx);
41
42
  };
42
43
  }
@@ -1 +1 @@
1
- {"version":3,"file":"OidcInteractions.js","sourceRoot":"","sources":["../../../src/services/OidcInteractions.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,QAAQ,EAAE,gBAAgB,EAAmB,eAAe,EAA0B,MAAM,cAAc,CAAC;AACnH,OAAO,EAAC,GAAG,EAAC,MAAM,YAAY,CAAC;AAC/B,OAAO,EAAC,MAAM,EAAE,UAAU,EAAE,eAAe,EAAC,MAAM,UAAU,CAAC;AAC7D,OAAO,EAAC,WAAW,EAAE,mBAAmB,EAAE,YAAY,EAAC,MAAM,wBAAwB,CAAC;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,eAAe,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,mBAAmB,CAAC,CAAC;YAC/E,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;YAEtC,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CA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eAAe;kDAAC;AAG1B;IADC,QAAQ,CAAC,KAAK,CAAC;;6CACP;AAGT;IADC,QAAQ,CAAC,MAAM,CAAC;;sDACU;AARhB,gBAAgB;IAD5B,UAAU,EAAE;GACA,gBAAgB,CAsD5B;SAtDY,gBAAgB","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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CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,OAAO,KAAK,YAAY,CAAC,CAAC;QAEhH,0BAA0B;QAC1B,IAAI,CAAC,oBAAoB,EAAE;YACzB,OAAO,EAAE,CAAC;SACX;QAED,OAAO,oBAAoB,CAAC,QAAQ;aACjC,GAAG,CAAC,CAAC,KAAoB,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,KAAK,CAAE,CAAC;aAChE,MAAM,CAAC,CAAC,QAAkB,EAAE,EAAE,CAAC,QAAQ,EAAE,OAAO,KAAK,WAAW,CAAC,CAAC;IACvE,CAAC;IAED,sBAAsB,CAAC,IAAY;QACjC,OAAO,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACrC,CAAC;IAED,qBAAqB,CAAC,IAAY;QAChC,MAAM,WAAW,GAAG,IAAI,CAAC,sBAAsB,CAAC,IAAI,CAAC,CAAC;QAEtD,IAAI,WAAW,EAAE;YACf,MAAM,QAAQ,GAAG,gBAAgB,CAAC,GAAG,CAAC,WAAW,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;YACvE,OAAO,CAAC,GAAoB,EAAE,EAAE;gBAC9B,uCAAuC;gBACvC,GAAG,CAAC,QAAQ,GAAG,QAAQ,CAAC;gBACxB,OAAO,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,CAAC;YAC/C,CAAC,CAAC;SACH;IACH,CAAC;CACF,CAAA;AApDC;IADC,MAAM,EAAE;8BACC,eAAe;kDAAC;AAG1B;IADC,QAAQ,CAAC,KAAK,CAAC;;6CACP;AAGT;IADC,QAAQ,CAAC,MAAM,CAAC;;sDACU;AARhB,gBAAgB;IAD5B,UAAU,EAAE;GACA,gBAAgB,CAsD5B;SAtDY,gBAAgB","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 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"]}
@@ -0,0 +1,3 @@
1
+ import { BadRequest } from "@tsed/exceptions";
2
+ export declare class OidcBadInteractionName extends BadRequest {
3
+ }
@@ -0,0 +1,9 @@
1
+ import { UnknownObject } from "oidc-provider";
2
+ import { OidcClient } from "./interfaces";
3
+ export declare type OidcInteractionPromptProps<Props = Record<string, any>> = {
4
+ client: OidcClient;
5
+ uid: string;
6
+ grantId: string;
7
+ details: UnknownObject;
8
+ params: Record<string, any>;
9
+ } & Props;
@@ -13,9 +13,11 @@ export * from "./decorators/params";
13
13
  export * from "./decorators/prompt";
14
14
  export * from "./decorators/uid";
15
15
  export * from "./domain/OidcAccountsMethods";
16
+ export * from "./domain/OidcBadInteractionName";
16
17
  export * from "./domain/OidcInteraction";
17
18
  export * from "./domain/OidcInteractionMethods";
18
19
  export * from "./domain/OidcInteractionOptions";
20
+ export * from "./domain/OidcInteractionPromptProps";
19
21
  export * from "./domain/OidcSettings";
20
22
  export * from "./domain/interfaces";
21
23
  export * from "./middlewares/OidcInteractionMiddleware";
@@ -4,13 +4,14 @@ import { Account, InteractionResults, PromptDetail, Provider } from "oidc-provid
4
4
  import { OidcSession } from "../decorators/oidcSession";
5
5
  import { OidcClient } from "../domain/interfaces";
6
6
  import { OidcInteraction } from "../domain/OidcInteraction";
7
+ import { OidcInteractionPromptProps } from "../domain/OidcInteractionPromptProps";
7
8
  import { OidcInteractions } from "./OidcInteractions";
8
9
  import { OidcProvider } from "./OidcProvider";
9
10
  export declare class OidcInteractionContext {
10
11
  env: Env;
11
12
  protected oidcProvider: OidcProvider;
12
13
  protected oidcInteractions: OidcInteractions;
13
- protected context: PlatformContext;
14
+ protected $ctx: PlatformContext;
14
15
  protected raw: OidcInteraction;
15
16
  get session(): OidcSession | undefined;
16
17
  get prompt(): PromptDetail;
@@ -25,10 +26,13 @@ export declare class OidcInteractionContext {
25
26
  interactionResult(result: InteractionResults, options?: {
26
27
  mergeWithLastSubmission?: boolean;
27
28
  }): Promise<string>;
29
+ interactionPrompt(options: Record<string, any>): Promise<OidcInteractionPromptProps>;
28
30
  render(view: string, result: any): Promise<string>;
29
31
  save(ttl: number): Promise<string>;
30
32
  findClient(clientId?: string): Promise<OidcClient | undefined>;
31
33
  findAccount(sub?: string, token?: any): Promise<Account | undefined>;
32
34
  getGrant(): Promise<InstanceType<Provider["Grant"]>>;
35
+ checkInteractionName(name: string): void;
36
+ checkClientId(clientId?: any): Promise<void>;
33
37
  debug(obj?: any): any;
34
38
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsed/oidc-provider",
3
- "version": "7.0.0-beta.13",
3
+ "version": "7.0.0-beta.16",
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.0.0-beta.13",
25
+ "@tsed/adapters": "7.0.0-beta.16",
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.0.0-beta.13",
35
- "@tsed/core": "7.0.0-beta.13",
36
- "@tsed/di": "7.0.0-beta.13",
37
- "@tsed/exceptions": "7.0.0-beta.13",
34
+ "@tsed/common": "7.0.0-beta.16",
35
+ "@tsed/core": "7.0.0-beta.16",
36
+ "@tsed/di": "7.0.0-beta.16",
37
+ "@tsed/exceptions": "7.0.0-beta.16",
38
38
  "@types/lowdb": "1.0.11",
39
39
  "@types/oidc-provider": "^7.1.1",
40
40
  "@types/uuid": "8.3.4",
@@ -42,7 +42,7 @@
42
42
  "oidc-provider": "7.11.1"
43
43
  },
44
44
  "peerDependencies": {
45
- "@tsed/common": "^7.0.0-beta.13",
45
+ "@tsed/common": "^7.0.0-beta.16",
46
46
  "oidc-provider": ">=7.3.0"
47
47
  },
48
48
  "peerDependenciesMeta": {
package/readme.md CHANGED
@@ -106,7 +106,7 @@ Support this project by becoming a sponsor. Your logo will show up here with a l
106
106
 
107
107
  The MIT License (MIT)
108
108
 
109
- Copyright (c) 2016 - 2018 Romain Lenzotti
109
+ Copyright (c) 2016 - 2022 Romain Lenzotti
110
110
 
111
111
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
112
112