@tsed/oidc-provider 6.120.0 → 6.122.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/domain/OidcBadInteractionName.js +8 -0
- package/lib/cjs/domain/OidcBadInteractionName.js.map +1 -0
- package/lib/cjs/domain/OidcInteractionPromptProps.js +3 -0
- package/lib/cjs/domain/OidcInteractionPromptProps.js.map +1 -0
- package/lib/cjs/index.js +2 -0
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/services/OidcInteractionContext.js +33 -1
- package/lib/cjs/services/OidcInteractionContext.js.map +1 -1
- package/lib/esm/domain/OidcBadInteractionName.js +4 -0
- package/lib/esm/domain/OidcBadInteractionName.js.map +1 -0
- package/lib/esm/domain/OidcInteractionPromptProps.js +2 -0
- package/lib/esm/domain/OidcInteractionPromptProps.js.map +1 -0
- package/lib/esm/index.js +2 -0
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/services/OidcInteractionContext.js +33 -1
- package/lib/esm/services/OidcInteractionContext.js.map +1 -1
- package/lib/types/domain/OidcBadInteractionName.d.ts +3 -0
- package/lib/types/domain/OidcInteractionPromptProps.d.ts +9 -0
- package/lib/types/index.d.ts +2 -0
- package/lib/types/services/OidcInteractionContext.d.ts +4 -0
- package/package.json +7 -7
|
@@ -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 @@
|
|
|
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);
|
package/lib/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,uDAA6B;AAC7B,gEAAsC;AACtC,+DAAqC;AACrC,mEAAyC;AACzC,oEAA0C;AAC1C,+DAAqC;AACrC,+DAAqC;AACrC,mEAAyC;AACzC,8DAAoC;AACpC,8DAAoC;AACpC,2DAAiC;AACjC,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"]}
|
|
@@ -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");
|
|
@@ -45,6 +47,21 @@ let OidcInteractionContext = class OidcInteractionContext {
|
|
|
45
47
|
async interactionResult(result, options = { mergeWithLastSubmission: false }) {
|
|
46
48
|
return this.oidcProvider.get().interactionResult(this.context.getReq(), this.context.getRes(), result, options);
|
|
47
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
|
+
};
|
|
64
|
+
}
|
|
48
65
|
async render(view, result) {
|
|
49
66
|
return this.context.response.render(view, result);
|
|
50
67
|
}
|
|
@@ -52,7 +69,11 @@ let OidcInteractionContext = class OidcInteractionContext {
|
|
|
52
69
|
return this.raw.save(ttl);
|
|
53
70
|
}
|
|
54
71
|
async findClient(clientId = this.params.client_id) {
|
|
55
|
-
|
|
72
|
+
const key = `$client:${clientId}`;
|
|
73
|
+
if (!this.context.has(key)) {
|
|
74
|
+
this.context.set(key, await this.oidcProvider.get().Client.find(clientId));
|
|
75
|
+
}
|
|
76
|
+
return this.context.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) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OidcInteractionContext.js","sourceRoot":"","sources":["../../../src/services/OidcInteractionContext.ts"],"names":[],"mappings":";;;;AAAA,yCAA6E;AAC7E,qCAA+B;AAC/B,iCAA4C;
|
|
1
|
+
{"version":3,"file":"OidcInteractionContext.js","sourceRoot":"","sources":["../../../src/services/OidcInteractionContext.ts"],"names":[],"mappings":";;;;AAAA,yCAA6E;AAC7E,qCAA+B;AAC/B,iCAA4C;AAC5C,iDAA8C;AAI9C,6EAAwE;AAGxE,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;IAC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OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,SAAS;YAC5D,GAAG,EAAE;gBACH,MAAM,EAAE,IAAI,CAAC,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;AApJC;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,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 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 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.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 const key = `$client:${clientId}`;\n if (!this.context.has(key)) {\n this.context.set(key, await this.oidcProvider.get().Client.find(clientId));\n }\n\n return this.context.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"]}
|
|
@@ -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 @@
|
|
|
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";
|
package/lib/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,cAAc,CAAC;AAC7B,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,0BAA0B,CAAC;AACzC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,0BAA0B,CAAC;AACzC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,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"]}
|
|
@@ -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";
|
|
@@ -42,6 +44,21 @@ let OidcInteractionContext = class OidcInteractionContext {
|
|
|
42
44
|
async interactionResult(result, options = { mergeWithLastSubmission: false }) {
|
|
43
45
|
return this.oidcProvider.get().interactionResult(this.context.getReq(), this.context.getRes(), result, options);
|
|
44
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
|
+
};
|
|
61
|
+
}
|
|
45
62
|
async render(view, result) {
|
|
46
63
|
return this.context.response.render(view, result);
|
|
47
64
|
}
|
|
@@ -49,7 +66,11 @@ let OidcInteractionContext = class OidcInteractionContext {
|
|
|
49
66
|
return this.raw.save(ttl);
|
|
50
67
|
}
|
|
51
68
|
async findClient(clientId = this.params.client_id) {
|
|
52
|
-
|
|
69
|
+
const key = `$client:${clientId}`;
|
|
70
|
+
if (!this.context.has(key)) {
|
|
71
|
+
this.context.set(key, await this.oidcProvider.get().Client.find(clientId));
|
|
72
|
+
}
|
|
73
|
+
return this.context.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) {
|
|
@@ -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;
|
|
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,EAAC,MAAM,gBAAgB,CAAC;AACrC,OAAO,EAAC,gBAAgB,EAAC,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAI5C,IAAa,sBAAsB,GAAnC,MAAa,sBAAsB;IAEjC,GAAG,CAAM;IA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AAC,QAAQ,CAAC,CAAC;QAE/C,IAAI,CAAC,MAAM,EAAE;YACX,MAAM,IAAI,YAAY,CAAC,qBAAqB,QAAQ,EAAE,CAAC,CAAC;SACzD;IACH,CAAC;IAED,KAAK,CAAC,GAAS;QACb,0BAA0B;QAC1B,IAAI,IAAI,CAAC,GAAG,KAAK,GAAG,CAAC,IAAI,EAAE;YACzB,OAAO,EAAC,OAAO,EAAE,SAAS,EAAE,GAAG,EAAE,EAAC,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAC,EAAC,CAAC;SAC1E;QAED,IAAI,GAAG,EAAE;YACP,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC;SACnB;QAED,OAAO;YACL,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,SAAS;YAC5D,GAAG,EAAE;gBACH,MAAM,EAAE,IAAI,CAAC,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;AApJC;IADC,QAAQ,CAAC,KAAK,CAAC;;mDACP;AAGT;IADC,MAAM,EAAE;8BACe,YAAY;4DAAC;AAGrC;IADC,MAAM,EAAE;8BACmB,gBAAgB;gEAAC;AAG7C;IADC,MAAM,EAAE;8BACU,eAAe;uDAAC;AAXxB,sBAAsB;IAFlC,UAAU,EAAE;IACZ,KAAK,CAAC,aAAa,CAAC,OAAO,CAAC;GAChB,sBAAsB,CAsJlC;SAtJY,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 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 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.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 const key = `$client:${clientId}`;\n if (!this.context.has(key)) {\n this.context.set(key, await this.oidcProvider.get().Client.find(clientId));\n }\n\n return this.context.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"]}
|
|
@@ -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;
|
package/lib/types/index.d.ts
CHANGED
|
@@ -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,6 +4,7 @@ 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 {
|
|
@@ -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": "6.
|
|
3
|
+
"version": "6.122.0",
|
|
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": "6.
|
|
25
|
+
"@tsed/adapters": "6.122.0",
|
|
26
26
|
"express-urlrewrite": "^1.4.0",
|
|
27
27
|
"jose2": "npm:jose@^2.0.4",
|
|
28
28
|
"koa-mount": "^4.0.0",
|
|
@@ -32,17 +32,17 @@
|
|
|
32
32
|
"uuid": "8.3.2"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@tsed/common": "6.
|
|
36
|
-
"@tsed/core": "6.
|
|
37
|
-
"@tsed/di": "6.
|
|
38
|
-
"@tsed/exceptions": "6.
|
|
35
|
+
"@tsed/common": "6.122.0",
|
|
36
|
+
"@tsed/core": "6.122.0",
|
|
37
|
+
"@tsed/di": "6.122.0",
|
|
38
|
+
"@tsed/exceptions": "6.122.0",
|
|
39
39
|
"@types/lowdb": "1.0.11",
|
|
40
40
|
"@types/oidc-provider": "^7.1.1",
|
|
41
41
|
"@types/uuid": "8.3.4",
|
|
42
42
|
"oidc-provider": "7.11.1"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
|
-
"@tsed/common": "^6.
|
|
45
|
+
"@tsed/common": "^6.122.0",
|
|
46
46
|
"oidc-provider": ">=7.3.0"
|
|
47
47
|
},
|
|
48
48
|
"peerDependenciesMeta": {
|