@tsed/oidc-provider 7.0.0-beta.14 → 7.0.0-beta.17
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/coverage.json +6 -0
- package/jest.config.js +1 -6
- package/lib/cjs/domain/OidcAccountsMethods.js.map +1 -1
- 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/domain/OidcSettings.js.map +1 -1
- package/lib/cjs/index.js +2 -0
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/middlewares/OidcInteractionMiddleware.js +5 -27
- package/lib/cjs/middlewares/OidcInteractionMiddleware.js.map +1 -1
- package/lib/cjs/services/OidcInteractionContext.js +50 -8
- package/lib/cjs/services/OidcInteractionContext.js.map +1 -1
- package/lib/cjs/services/OidcProvider.js +7 -7
- package/lib/cjs/services/OidcProvider.js.map +1 -1
- package/lib/esm/domain/OidcAccountsMethods.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/domain/OidcSettings.js.map +1 -1
- package/lib/esm/index.js +2 -0
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/middlewares/OidcInteractionMiddleware.js +7 -29
- package/lib/esm/middlewares/OidcInteractionMiddleware.js.map +1 -1
- package/lib/esm/services/OidcInteractionContext.js +51 -9
- package/lib/esm/services/OidcInteractionContext.js.map +1 -1
- package/lib/esm/services/OidcProvider.js +8 -8
- package/lib/esm/services/OidcProvider.js.map +1 -1
- package/lib/types/domain/OidcAccountsMethods.d.ts +1 -2
- package/lib/types/domain/OidcBadInteractionName.d.ts +3 -0
- package/lib/types/domain/OidcInteractionPromptProps.d.ts +9 -0
- package/lib/types/domain/OidcSettings.d.ts +9 -1
- package/lib/types/index.d.ts +2 -0
- package/lib/types/middlewares/OidcInteractionMiddleware.d.ts +3 -5
- package/lib/types/services/OidcInteractionContext.d.ts +5 -1
- package/lib/types/services/OidcProvider.d.ts +3 -3
- package/package.json +7 -7
- package/readme.md +2 -1
package/coverage.json
ADDED
package/jest.config.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OidcAccountsMethods.js","sourceRoot":"","sources":["../../../src/domain/OidcAccountsMethods.ts"],"names":[],"mappings":"","sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"OidcAccountsMethods.js","sourceRoot":"","sources":["../../../src/domain/OidcAccountsMethods.ts"],"names":[],"mappings":"","sourcesContent":["import {Provider, Account} from \"oidc-provider\";\n\nexport type AuthorizationCode = InstanceType<Provider[\"AuthorizationCode\"]>;\nexport type AccessToken = InstanceType<Provider[\"AccessToken\"]>;\nexport type DeviceCode = InstanceType<Provider[\"DeviceCode\"]>;\nexport type BackchannelAuthenticationRequest = InstanceType<Provider[\"BackchannelAuthenticationRequest\"]>;\n\nexport interface OidcAccountsMethods {\n findAccount(\n id: string,\n token: AuthorizationCode | AccessToken | DeviceCode | BackchannelAuthenticationRequest | undefined\n ): Promise<Account | undefined>;\n}\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OidcBadInteractionName = void 0;
|
|
4
|
+
const exceptions_1 = require("@tsed/exceptions");
|
|
5
|
+
class OidcBadInteractionName extends exceptions_1.BadRequest {
|
|
6
|
+
}
|
|
7
|
+
exports.OidcBadInteractionName = OidcBadInteractionName;
|
|
8
|
+
//# sourceMappingURL=OidcBadInteractionName.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OidcBadInteractionName.js","sourceRoot":"","sources":["../../../src/domain/OidcBadInteractionName.ts"],"names":[],"mappings":";;;AAAA,iDAA4C;AAE5C,MAAa,sBAAuB,SAAQ,uBAAU;CAAG;AAAzD,wDAAyD","sourcesContent":["import {BadRequest} from \"@tsed/exceptions\";\n\nexport class OidcBadInteractionName extends BadRequest {}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OidcInteractionPromptProps.js","sourceRoot":"","sources":["../../../src/domain/OidcInteractionPromptProps.ts"],"names":[],"mappings":"","sourcesContent":["import {UnknownObject} from \"oidc-provider\";\nimport {OidcClient} from \"./interfaces\";\n\nexport type OidcInteractionPromptProps<Props = Record<string, any>> = {\n client: OidcClient;\n uid: string;\n grantId: string;\n details: UnknownObject;\n params: Record<string, any>;\n} & Props;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OidcSettings.js","sourceRoot":"","sources":["../../../src/domain/OidcSettings.ts"],"names":[],"mappings":"","sourcesContent":["import {Type} from \"@tsed/core\";\nimport {JwksKeyParameters} from \"@tsed/jwks\";\nimport {Configuration} from \"oidc-provider\";\nimport {OidcAccountsMethods} from \"./OidcAccountsMethods\";\n\nexport interface OidcSettings extends Configuration {\n /**\n * Path on which the oidc-provider instance is mounted.\n */\n path?: string;\n /**\n * Issuer URI. By default Ts.ED create issuer with http://localhost:${httpPort}\n */\n issuer?: string;\n /**\n * Path to store jwks keys.\n */\n jwksPath?: string;\n /**\n * Generate jwks from given certificates\n */\n certificates?: JwksKeyParameters[];\n /**\n * Secure keys.\n */\n secureKey?: string[];\n /**\n * Enable proxy.\n */\n proxy?: boolean;\n /**\n *
|
|
1
|
+
{"version":3,"file":"OidcSettings.js","sourceRoot":"","sources":["../../../src/domain/OidcSettings.ts"],"names":[],"mappings":"","sourcesContent":["import {Type} from \"@tsed/core\";\nimport {JwksKeyParameters} from \"@tsed/jwks\";\nimport {Configuration} from \"oidc-provider\";\nimport {OidcAccountsMethods} from \"./OidcAccountsMethods\";\n\nexport interface OidcSettings extends Configuration {\n /**\n * force the secure cookie. By default, in dev mode it's disabled and in production it's enabled.\n */\n secureCookies?: boolean;\n /**\n * Path on which the oidc-provider instance is mounted.\n */\n path?: string;\n /**\n * Issuer URI. By default, Ts.ED create issuer with http://localhost:${httpPort}\n */\n issuer?: string;\n /**\n * Path to store jwks keys.\n */\n jwksPath?: string;\n /**\n * Generate jwks from given certificates\n */\n certificates?: JwksKeyParameters[];\n /**\n * Secure keys.\n */\n secureKey?: string[];\n /**\n * Enable proxy.\n */\n proxy?: boolean;\n /**\n * Allow redirect_uri on HTTP protocol and localhost domain.\n */\n allowHttpLocalhost?: boolean;\n /**\n * Injectable service to manage accounts.\n */\n Accounts?: Type<OidcAccountsMethods>;\n}\n\ndeclare global {\n namespace TsED {\n interface Configuration {\n oidc: OidcSettings;\n }\n }\n}\n"]}
|
package/lib/cjs/index.js
CHANGED
|
@@ -16,9 +16,11 @@ tslib_1.__exportStar(require("./decorators/params"), exports);
|
|
|
16
16
|
tslib_1.__exportStar(require("./decorators/prompt"), exports);
|
|
17
17
|
tslib_1.__exportStar(require("./decorators/uid"), exports);
|
|
18
18
|
tslib_1.__exportStar(require("./domain/OidcAccountsMethods"), exports);
|
|
19
|
+
tslib_1.__exportStar(require("./domain/OidcBadInteractionName"), exports);
|
|
19
20
|
tslib_1.__exportStar(require("./domain/OidcInteraction"), exports);
|
|
20
21
|
tslib_1.__exportStar(require("./domain/OidcInteractionMethods"), exports);
|
|
21
22
|
tslib_1.__exportStar(require("./domain/OidcInteractionOptions"), exports);
|
|
23
|
+
tslib_1.__exportStar(require("./domain/OidcInteractionPromptProps"), exports);
|
|
22
24
|
tslib_1.__exportStar(require("./domain/OidcSettings"), exports);
|
|
23
25
|
tslib_1.__exportStar(require("./domain/interfaces"), exports);
|
|
24
26
|
tslib_1.__exportStar(require("./middlewares/OidcInteractionMiddleware"), exports);
|
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"]}
|
|
@@ -3,39 +3,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.OidcInteractionMiddleware = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const common_1 = require("@tsed/common");
|
|
6
|
-
const constants_1 = require("../constants/constants");
|
|
7
6
|
const OidcInteractionContext_1 = require("../services/OidcInteractionContext");
|
|
8
|
-
const OidcInteractions_1 = require("../services/OidcInteractions");
|
|
9
7
|
let OidcInteractionMiddleware = class OidcInteractionMiddleware {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const oidcInteraction = this.injector.invoke(OidcInteractionContext_1.OidcInteractionContext, context.container);
|
|
14
|
-
const interactionDetails = await oidcInteraction.interactionDetails();
|
|
15
|
-
const { uid, prompt, params, session, grantId } = interactionDetails;
|
|
16
|
-
context.set(constants_1.INTERACTION_CONTEXT, oidcInteraction);
|
|
17
|
-
context.set(constants_1.INTERACTION_DETAILS, interactionDetails);
|
|
18
|
-
context.set(constants_1.INTERACTION_UID, uid);
|
|
19
|
-
context.set(constants_1.INTERACTION_PROMPT, prompt);
|
|
20
|
-
context.set(constants_1.INTERACTION_PARAMS, params);
|
|
21
|
-
context.set(constants_1.INTERACTION_GRANT_ID, grantId);
|
|
22
|
-
context.set(constants_1.INTERACTION_SESSION, session);
|
|
8
|
+
oidcInteractionContext;
|
|
9
|
+
async use() {
|
|
10
|
+
await this.oidcInteractionContext.interactionDetails();
|
|
23
11
|
}
|
|
24
12
|
};
|
|
25
13
|
tslib_1.__decorate([
|
|
26
14
|
(0, common_1.Inject)(),
|
|
27
|
-
tslib_1.__metadata("design:type",
|
|
28
|
-
], OidcInteractionMiddleware.prototype, "
|
|
29
|
-
tslib_1.__decorate([
|
|
30
|
-
(0, common_1.Inject)(),
|
|
31
|
-
tslib_1.__metadata("design:type", common_1.InjectorService)
|
|
32
|
-
], OidcInteractionMiddleware.prototype, "injector", void 0);
|
|
33
|
-
tslib_1.__decorate([
|
|
34
|
-
tslib_1.__param(0, (0, common_1.Context)()),
|
|
35
|
-
tslib_1.__metadata("design:type", Function),
|
|
36
|
-
tslib_1.__metadata("design:paramtypes", [Object]),
|
|
37
|
-
tslib_1.__metadata("design:returntype", Promise)
|
|
38
|
-
], OidcInteractionMiddleware.prototype, "use", null);
|
|
15
|
+
tslib_1.__metadata("design:type", OidcInteractionContext_1.OidcInteractionContext)
|
|
16
|
+
], OidcInteractionMiddleware.prototype, "oidcInteractionContext", void 0);
|
|
39
17
|
OidcInteractionMiddleware = tslib_1.__decorate([
|
|
40
18
|
(0, common_1.Middleware)()
|
|
41
19
|
], OidcInteractionMiddleware);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OidcInteractionMiddleware.js","sourceRoot":"","sources":["../../../src/middlewares/OidcInteractionMiddleware.ts"],"names":[],"mappings":";;;;AAAA,yCAA0E;
|
|
1
|
+
{"version":3,"file":"OidcInteractionMiddleware.js","sourceRoot":"","sources":["../../../src/middlewares/OidcInteractionMiddleware.ts"],"names":[],"mappings":";;;;AAAA,yCAA0E;AAU1E,+EAA0E;AAI1E,IAAa,yBAAyB,GAAtC,MAAa,yBAAyB;IAE1B,sBAAsB,CAAyB;IAEzD,KAAK,CAAC,GAAG;QACP,MAAM,IAAI,CAAC,sBAAsB,CAAC,kBAAkB,EAAE,CAAC;IACzD,CAAC;CACF,CAAA;AALC;IADC,IAAA,eAAM,GAAE;sCACyB,+CAAsB;yEAAC;AAF9C,yBAAyB;IADrC,IAAA,mBAAU,GAAE;GACA,yBAAyB,CAOrC;AAPY,8DAAyB","sourcesContent":["import {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 oidcInteractionContext: OidcInteractionContext;\n\n async use() {\n await this.oidcInteractionContext.interactionDetails();\n }\n}\n"]}
|
|
@@ -5,6 +5,9 @@ const tslib_1 = require("tslib");
|
|
|
5
5
|
const common_1 = require("@tsed/common");
|
|
6
6
|
const core_1 = require("@tsed/core");
|
|
7
7
|
const di_1 = require("@tsed/di");
|
|
8
|
+
const exceptions_1 = require("@tsed/exceptions");
|
|
9
|
+
const constants_1 = require("../constants/constants");
|
|
10
|
+
const OidcBadInteractionName_1 = require("../domain/OidcBadInteractionName");
|
|
8
11
|
const debug_1 = require("../utils/debug");
|
|
9
12
|
const OidcInteractions_1 = require("./OidcInteractions");
|
|
10
13
|
const OidcProvider_1 = require("./OidcProvider");
|
|
@@ -13,7 +16,9 @@ let OidcInteractionContext = class OidcInteractionContext {
|
|
|
13
16
|
oidcProvider;
|
|
14
17
|
oidcInteractions;
|
|
15
18
|
$ctx;
|
|
16
|
-
raw
|
|
19
|
+
get raw() {
|
|
20
|
+
return this.$ctx.get(constants_1.INTERACTION_DETAILS);
|
|
21
|
+
}
|
|
17
22
|
get session() {
|
|
18
23
|
return this.raw.session;
|
|
19
24
|
}
|
|
@@ -36,8 +41,16 @@ let OidcInteractionContext = class OidcInteractionContext {
|
|
|
36
41
|
}
|
|
37
42
|
}
|
|
38
43
|
async interactionDetails() {
|
|
39
|
-
|
|
40
|
-
|
|
44
|
+
const raw = await this.oidcProvider.get().interactionDetails(this.$ctx.getReq(), this.$ctx.getRes());
|
|
45
|
+
const { uid, prompt, params, session, grantId } = raw;
|
|
46
|
+
this.$ctx.set(constants_1.INTERACTION_CONTEXT, this);
|
|
47
|
+
this.$ctx.set(constants_1.INTERACTION_DETAILS, raw);
|
|
48
|
+
this.$ctx.set(constants_1.INTERACTION_UID, uid);
|
|
49
|
+
this.$ctx.set(constants_1.INTERACTION_PROMPT, prompt);
|
|
50
|
+
this.$ctx.set(constants_1.INTERACTION_PARAMS, params);
|
|
51
|
+
this.$ctx.set(constants_1.INTERACTION_GRANT_ID, grantId);
|
|
52
|
+
this.$ctx.set(constants_1.INTERACTION_SESSION, session);
|
|
53
|
+
return raw;
|
|
41
54
|
}
|
|
42
55
|
async interactionFinished(result, options = { mergeWithLastSubmission: false }) {
|
|
43
56
|
return this.oidcProvider.get().interactionFinished(this.$ctx.getReq(), this.$ctx.getRes(), result, options);
|
|
@@ -45,6 +58,21 @@ let OidcInteractionContext = class OidcInteractionContext {
|
|
|
45
58
|
async interactionResult(result, options = { mergeWithLastSubmission: false }) {
|
|
46
59
|
return this.oidcProvider.get().interactionResult(this.$ctx.getReq(), this.$ctx.getRes(), result, options);
|
|
47
60
|
}
|
|
61
|
+
async interactionPrompt(options) {
|
|
62
|
+
const client = await this.findClient();
|
|
63
|
+
return {
|
|
64
|
+
client,
|
|
65
|
+
uid: this.uid,
|
|
66
|
+
grantId: this.grantId,
|
|
67
|
+
details: this.prompt.details,
|
|
68
|
+
params: {
|
|
69
|
+
...this.params,
|
|
70
|
+
...options.params
|
|
71
|
+
},
|
|
72
|
+
...options,
|
|
73
|
+
...this.debug()
|
|
74
|
+
};
|
|
75
|
+
}
|
|
48
76
|
async render(view, result) {
|
|
49
77
|
return this.$ctx.response.render(view, result);
|
|
50
78
|
}
|
|
@@ -52,7 +80,8 @@ let OidcInteractionContext = class OidcInteractionContext {
|
|
|
52
80
|
return this.raw.save(ttl);
|
|
53
81
|
}
|
|
54
82
|
async findClient(clientId = this.params.client_id) {
|
|
55
|
-
|
|
83
|
+
const key = `$client:${clientId}`;
|
|
84
|
+
return this.$ctx.cacheAsync(key, () => this.oidcProvider.get().Client.find(clientId));
|
|
56
85
|
}
|
|
57
86
|
async findAccount(sub, token) {
|
|
58
87
|
if (!sub && this.session) {
|
|
@@ -61,7 +90,10 @@ let OidcInteractionContext = class OidcInteractionContext {
|
|
|
61
90
|
if (!sub) {
|
|
62
91
|
return;
|
|
63
92
|
}
|
|
64
|
-
|
|
93
|
+
const key = `$account:${sub}`;
|
|
94
|
+
return this.$ctx.cacheAsync(key, (() => {
|
|
95
|
+
return this.oidcProvider.get().Account.findAccount(undefined, sub, token);
|
|
96
|
+
}));
|
|
65
97
|
}
|
|
66
98
|
async getGrant() {
|
|
67
99
|
const { Grant } = this.oidcProvider.get();
|
|
@@ -75,6 +107,17 @@ let OidcInteractionContext = class OidcInteractionContext {
|
|
|
75
107
|
clientId: this.params.client_id
|
|
76
108
|
});
|
|
77
109
|
}
|
|
110
|
+
checkInteractionName(name) {
|
|
111
|
+
if (this.prompt.name !== name) {
|
|
112
|
+
throw new OidcBadInteractionName_1.OidcBadInteractionName("Bad interaction name");
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
async checkClientId(clientId = this.params.client_id) {
|
|
116
|
+
const client = await this.findClient(clientId);
|
|
117
|
+
if (!client) {
|
|
118
|
+
throw new exceptions_1.Unauthorized(`Unknown client_id ${clientId}`);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
78
121
|
debug(obj) {
|
|
79
122
|
/* istanbul ignore next */
|
|
80
123
|
if (this.env === core_1.Env.PROD) {
|
|
@@ -105,12 +148,11 @@ tslib_1.__decorate([
|
|
|
105
148
|
tslib_1.__metadata("design:type", OidcInteractions_1.OidcInteractions)
|
|
106
149
|
], OidcInteractionContext.prototype, "oidcInteractions", void 0);
|
|
107
150
|
tslib_1.__decorate([
|
|
108
|
-
(0,
|
|
151
|
+
(0, common_1.InjectContext)(),
|
|
109
152
|
tslib_1.__metadata("design:type", common_1.PlatformContext)
|
|
110
153
|
], OidcInteractionContext.prototype, "$ctx", void 0);
|
|
111
154
|
OidcInteractionContext = tslib_1.__decorate([
|
|
112
|
-
(0, di_1.Injectable)()
|
|
113
|
-
(0, common_1.Scope)(common_1.ProviderScope.REQUEST)
|
|
155
|
+
(0, di_1.Injectable)()
|
|
114
156
|
], OidcInteractionContext);
|
|
115
157
|
exports.OidcInteractionContext = OidcInteractionContext;
|
|
116
158
|
//# sourceMappingURL=OidcInteractionContext.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OidcInteract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;sCACe,2BAAY;4DAAC;AAGrC;IADC,IAAA,WAAM,GAAE;sCACmB,mCAAgB;gEAAC;AAG7C;IADC,IAAA,WAAM,GAAE;sCACO,wBAAe;oDAAC;AAXrB,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 $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 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 return this.oidcProvider.get().Client.find(clientId);\n }\n\n async findAccount(sub?: string, token?: any): Promise<Account | undefined> {\n if (!sub && this.session) {\n sub = this.session?.accountId as any;\n }\n\n if (!sub) {\n return;\n }\n\n return this.oidcProvider.get().Account.findAccount(undefined as any, sub!, token);\n }\n\n async getGrant(): Promise<InstanceType<Provider[\"Grant\"]>> {\n const {Grant} = this.oidcProvider.get() as any;\n\n if (this.grantId) {\n // we'll be modifying existing grant in existing session\n // @ts-ignore\n return await (this.oidcProvider.get().find || Grant.find)(this.grantId);\n }\n\n return new Grant({\n accountId: this.session?.accountId,\n clientId: this.params.client_id\n });\n }\n\n debug(obj?: any): any {\n /* istanbul ignore next */\n if (this.env === Env.PROD) {\n return {session: undefined, dbg: {params: undefined, prompt: undefined}};\n }\n\n if (obj) {\n return debug(obj);\n }\n\n return {\n session: this.session ? this.debug(this.session) : undefined,\n dbg: {\n params: this.debug(this.params),\n prompt: this.debug(this.prompt)\n }\n };\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"OidcInteractionContext.js","sourceRoot":"","sources":["../../../src/services/OidcInteractionContext.ts"],"names":[],"mappings":";;;;AAAA,yCAAsE;AACtE,qCAA+B;AAC/B,iCAA4C;AAC5C,iDAA8C;AAE9C,sDAQgC;AAGhC,6EAAwE;AAGxE,0CAAqC;AACrC,yDAAoD;AACpD,iDAA4C;AAG5C,IAAa,sBAAsB,GAAnC,MAAa,sBAAsB;IAEjC,GAAG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AC,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;AAjKC;IADC,IAAA,iBAAQ,EAAC,KAAK,CAAC;;mDACP;AAGT;IADC,IAAA,WAAM,GAAE;sCACe,2BAAY;4DAAC;AAGrC;IADC,IAAA,WAAM,GAAE;sCACmB,mCAAgB;gEAAC;AAG7C;IADC,IAAA,sBAAa,GAAE;sCACA,wBAAe;oDAAC;AAXrB,sBAAsB;IADlC,IAAA,eAAU,GAAE;GACA,sBAAsB,CAmKlC;AAnKY,wDAAsB","sourcesContent":["import {Constant, InjectContext, PlatformContext} from \"@tsed/common\";\nimport {Env} from \"@tsed/core\";\nimport {Inject, Injectable} from \"@tsed/di\";\nimport {Unauthorized} from \"@tsed/exceptions\";\nimport {Account, InteractionResults, PromptDetail, Provider} from \"oidc-provider\";\nimport {\n INTERACTION_CONTEXT,\n INTERACTION_DETAILS,\n INTERACTION_GRANT_ID,\n INTERACTION_PARAMS,\n INTERACTION_PROMPT,\n INTERACTION_SESSION,\n INTERACTION_UID\n} from \"../constants/constants\";\nimport {OidcSession} from \"../decorators/oidcSession\";\nimport {OidcClient} from \"../domain/interfaces\";\nimport {OidcBadInteractionName} from \"../domain/OidcBadInteractionName\";\nimport {OidcInteraction} from \"../domain/OidcInteraction\";\nimport {OidcInteractionPromptProps} from \"../domain/OidcInteractionPromptProps\";\nimport {debug} from \"../utils/debug\";\nimport {OidcInteractions} from \"./OidcInteractions\";\nimport {OidcProvider} from \"./OidcProvider\";\n\n@Injectable()\nexport class OidcInteractionContext {\n @Constant(\"env\")\n env: Env;\n\n @Inject()\n protected oidcProvider: OidcProvider;\n\n @Inject()\n protected oidcInteractions: OidcInteractions;\n\n @InjectContext()\n protected $ctx: PlatformContext;\n\n get raw(): OidcInteraction {\n return this.$ctx.get(INTERACTION_DETAILS)!;\n }\n\n get session(): OidcSession | undefined {\n return this.raw.session as any;\n }\n\n get prompt(): PromptDetail {\n return this.raw.prompt;\n }\n\n get params(): Record<string, any> {\n return this.raw.params;\n }\n\n get uid(): string {\n return this.raw.uid;\n }\n\n get grantId(): string {\n return (this.raw as any).grantId;\n }\n\n async runInteraction(name: string = this.prompt.name) {\n const handler = this.oidcInteractions.getInteractionHandler(name);\n\n if (handler) {\n await handler(this.$ctx);\n }\n }\n\n async interactionDetails(): Promise<OidcInteraction> {\n const raw = await this.oidcProvider.get().interactionDetails(this.$ctx.getReq(), this.$ctx.getRes());\n\n const {uid, prompt, params, session, grantId} = raw as any;\n\n this.$ctx.set(INTERACTION_CONTEXT, this);\n this.$ctx.set(INTERACTION_DETAILS, raw);\n this.$ctx.set(INTERACTION_UID, uid);\n this.$ctx.set(INTERACTION_PROMPT, prompt);\n this.$ctx.set(INTERACTION_PARAMS, params);\n this.$ctx.set(INTERACTION_GRANT_ID, grantId);\n this.$ctx.set(INTERACTION_SESSION, session);\n\n return raw;\n }\n\n async interactionFinished(result: InteractionResults, options: {mergeWithLastSubmission?: boolean} = {mergeWithLastSubmission: false}) {\n return this.oidcProvider.get().interactionFinished(this.$ctx.getReq(), this.$ctx.getRes(), result, options);\n }\n\n async interactionResult(result: InteractionResults, options: {mergeWithLastSubmission?: boolean} = {mergeWithLastSubmission: false}) {\n return this.oidcProvider.get().interactionResult(this.$ctx.getReq(), this.$ctx.getRes(), result, options);\n }\n\n async interactionPrompt(options: Record<string, any>): Promise<OidcInteractionPromptProps> {\n const client = await this.findClient();\n\n return {\n client,\n uid: this.uid,\n grantId: this.grantId,\n details: this.prompt.details,\n params: {\n ...this.params,\n ...options.params\n },\n ...options,\n ...this.debug()\n };\n }\n\n async render(view: string, result: any): Promise<string> {\n return this.$ctx.response.render(view, result);\n }\n\n async save(ttl: number): Promise<string> {\n return this.raw.save(ttl);\n }\n\n async findClient(clientId: string = this.params.client_id): Promise<OidcClient | undefined> {\n const key = `$client:${clientId}`;\n\n return this.$ctx.cacheAsync(key, () => this.oidcProvider.get().Client.find(clientId));\n }\n\n async findAccount(sub?: string, token?: any): Promise<Account | undefined> {\n if (!sub && this.session) {\n sub = this.session?.accountId as any;\n }\n\n if (!sub) {\n return;\n }\n\n const key = `$account:${sub}`;\n\n return this.$ctx.cacheAsync<Account | undefined>(key, (() => {\n return this.oidcProvider.get().Account.findAccount(undefined as any, sub!, token);\n }) as any);\n }\n\n async getGrant(): Promise<InstanceType<Provider[\"Grant\"]>> {\n const {Grant} = this.oidcProvider.get() as any;\n\n if (this.grantId) {\n // we'll be modifying existing grant in existing session\n // @ts-ignore\n return await (this.oidcProvider.get().find || Grant.find)(this.grantId);\n }\n\n return new Grant({\n accountId: this.session?.accountId,\n clientId: this.params.client_id\n });\n }\n\n checkInteractionName(name: string) {\n if (this.prompt.name !== name) {\n throw new OidcBadInteractionName(\"Bad interaction name\");\n }\n }\n\n async checkClientId(clientId = this.params.client_id) {\n const client = await this.findClient(clientId);\n\n if (!client) {\n throw new Unauthorized(`Unknown client_id ${clientId}`);\n }\n }\n\n debug(obj?: any): any {\n /* istanbul ignore next */\n if (this.env === Env.PROD) {\n return {session: undefined, dbg: {params: undefined, prompt: undefined}};\n }\n\n if (obj) {\n return debug(obj);\n }\n\n return {\n session: this.session ? this.debug(this.session) : undefined,\n dbg: {\n params: this.debug(this.params),\n prompt: this.debug(this.prompt)\n }\n };\n }\n}\n"]}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.OidcProvider = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
+
const common_1 = require("@tsed/common");
|
|
5
6
|
const core_1 = require("@tsed/core");
|
|
6
7
|
const di_1 = require("@tsed/di");
|
|
7
8
|
const oidc_provider_1 = require("oidc-provider");
|
|
@@ -9,7 +10,6 @@ const constants_1 = require("../constants/constants");
|
|
|
9
10
|
const OidcAdapters_1 = require("./OidcAdapters");
|
|
10
11
|
const OidcInteractions_1 = require("./OidcInteractions");
|
|
11
12
|
const OidcJwks_1 = require("./OidcJwks");
|
|
12
|
-
const common_1 = require("@tsed/common");
|
|
13
13
|
let OidcProvider = class OidcProvider {
|
|
14
14
|
raw;
|
|
15
15
|
env;
|
|
@@ -28,7 +28,7 @@ let OidcProvider = class OidcProvider {
|
|
|
28
28
|
}
|
|
29
29
|
async getConfiguration() {
|
|
30
30
|
const [jwks, adapter] = await Promise.all([this.oidcJwks.getJwks(), this.adapters.createAdapterClass()]);
|
|
31
|
-
const { issuer, jwksPath, secureKey, proxy, Accounts, ...options } = this.oidc;
|
|
31
|
+
const { issuer, jwksPath, secureKey, proxy, Accounts, secureCookies = this.env == core_1.Env.PROD, ...options } = this.oidc;
|
|
32
32
|
const configuration = {
|
|
33
33
|
interactions: {
|
|
34
34
|
/* istanbul ignore next */
|
|
@@ -39,9 +39,9 @@ let OidcProvider = class OidcProvider {
|
|
|
39
39
|
jwks
|
|
40
40
|
};
|
|
41
41
|
if (Accounts) {
|
|
42
|
-
configuration.findAccount = (ctx, id, token) => this.injector.get(Accounts).findAccount(id, token
|
|
42
|
+
configuration.findAccount = (ctx, id, token) => this.injector.get(Accounts).findAccount(id, token);
|
|
43
43
|
}
|
|
44
|
-
if (
|
|
44
|
+
if (secureCookies) {
|
|
45
45
|
(0, core_1.setValue)(configuration, "cookies.short.secure", true);
|
|
46
46
|
(0, core_1.setValue)(configuration, "cookies.long.secure", true);
|
|
47
47
|
}
|
|
@@ -72,10 +72,10 @@ let OidcProvider = class OidcProvider {
|
|
|
72
72
|
* Create a new instance of OidcProvider
|
|
73
73
|
*/
|
|
74
74
|
async create() {
|
|
75
|
-
const { proxy, secureKey } = this.oidc;
|
|
75
|
+
const { proxy = this.env === core_1.Env.PROD, secureKey, allowHttpLocalhost = this.env !== core_1.Env.PROD } = this.oidc;
|
|
76
76
|
const configuration = await this.getConfiguration();
|
|
77
77
|
const oidcProvider = new oidc_provider_1.Provider(this.getIssuer(), configuration);
|
|
78
|
-
if (proxy
|
|
78
|
+
if (proxy) {
|
|
79
79
|
// istanbul ignore next
|
|
80
80
|
switch (this.platformName) {
|
|
81
81
|
default:
|
|
@@ -91,7 +91,7 @@ let OidcProvider = class OidcProvider {
|
|
|
91
91
|
oidcProvider.app.keys = secureKey;
|
|
92
92
|
}
|
|
93
93
|
this.raw = oidcProvider;
|
|
94
|
-
if (
|
|
94
|
+
if (allowHttpLocalhost) {
|
|
95
95
|
this.allowHttpLocalhost();
|
|
96
96
|
}
|
|
97
97
|
await this.injector.emit("$onCreateOIDC", this.raw);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OidcProvider.js","sourceRoot":"","sources":["../../../src/services/OidcProvider.ts"],"names":[],"mappings":";;;;AAAA,qCAAyC;AACzC,iCAAuE;AACvE,iDAAyF;AACzF,sDAAoD;AACpD,iDAA4C;AAC5C,yDAAoD;AACpD,yCAAoC;AACpC,yCAAiD;AAKjD,IAAa,YAAY,GAAzB,MAAa,YAAY;IACvB,GAAG,CAAe;IAGR,GAAG,CAAM;IAGT,QAAQ,CAAkB;IAG1B,SAAS,CAAkB;IAG3B,MAAM,CAAS;IAGf,IAAI,CAAe;IAGnB,YAAY,CAAS;IAGrB,QAAQ,CAAW;IAGnB,gBAAgB,CAAmB;IAGnC,QAAQ,CAAe;IAGvB,QAAQ,CAAkB;IAG1B,GAAG,CAAsB;IAEnC,gBAAgB;QACd,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;IACrB,CAAC;IAED,KAAK,CAAC,gBAAgB;QACpB,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,EAAE,IAAI,CAAC,QAAQ,CAAC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I,iCAAiB,CAAC,MAAM,CAAC;wBAC3B,IAAI;wBACJ,GAAG,OAAO;qBACX,CAAC,CACH,CAAC;iBACH;gBAED,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;gBAEnD,IAAI,QAAQ,CAAC,SAAS,EAAE;oBACtB,QAAQ,CAAC,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;iBACtC;YACH,CAAC,CAAC,CAAC;SACJ;QAED,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,kBAAkB,EAAE,MAAM,CAAC,CAAC;IACzD,CAAC;CACF,CAAA;AAjLC;IADC,IAAA,aAAQ,EAAC,KAAK,CAAC;;yCACG;AAGnB;IADC,IAAA,aAAQ,EAAC,UAAU,CAAC;;8CACe;AAGpC;IADC,IAAA,aAAQ,EAAC,WAAW,CAAC;;+CACe;AAGrC;IADC,IAAA,aAAQ,EAAC,aAAa,EAAE,EAAE,CAAC;;4CACH;AAGzB;IADC,IAAA,aAAQ,EAAC,MAAM,CAAC;;0CACY;AAG7B;IADC,IAAA,aAAQ,EAAC,eAAe,CAAC;;kDACK;AAG/B;IADC,IAAA,WAAM,GAAE;sCACW,mBAAQ;8CAAC;AAG7B;IADC,IAAA,WAAM,GAAE;sCACmB,mCAAgB;sDAAC;AAG7C;IADC,IAAA,WAAM,GAAE;sCACW,2BAAY;8CAAC;AAGjC;IADC,IAAA,WAAM,GAAE;sCACW,oBAAe;8CAAC;AAGpC;IADC,IAAA,WAAM,GAAE;sCACM,4BAAmB;yCAAC;AAlCxB,YAAY;IADxB,IAAA,eAAU,GAAE;GACA,YAAY,CAqLxB;AArLY,oCAAY","sourcesContent":["import {Env, setValue} from \"@tsed/core\";\nimport {Constant, Inject, Injectable, InjectorService} from \"@tsed/di\";\nimport {Provider as OIDCProvider, Configuration, interactionPolicy} from \"oidc-provider\";\nimport {INTERACTIONS} from \"../constants/constants\";\nimport {OidcAdapters} from \"./OidcAdapters\";\nimport {OidcInteractions} from \"./OidcInteractions\";\nimport {OidcJwks} from \"./OidcJwks\";\nimport {PlatformApplication} from \"@tsed/common\";\nimport {OidcSettings} from \"../domain/OidcSettings\";\nimport {OidcAccountsMethods} from \"../domain/OidcAccountsMethods\";\n\n@Injectable()\nexport class OidcProvider {\n raw: OIDCProvider;\n\n @Constant(\"env\")\n protected env: Env;\n\n @Constant(\"httpPort\")\n protected httpPort: number | string;\n\n @Constant(\"httpsPort\")\n protected httpsPort: number | string;\n\n @Constant(\"oidc.issuer\", \"\")\n protected issuer: string;\n\n @Constant(\"oidc\")\n protected oidc: OidcSettings;\n\n @Constant(\"PLATFORM_NAME\")\n protected platformName: string;\n\n @Inject()\n protected oidcJwks: OidcJwks;\n\n @Inject()\n protected oidcInteractions: OidcInteractions;\n\n @Inject()\n protected adapters: OidcAdapters;\n\n @Inject()\n protected injector: InjectorService;\n\n @Inject()\n protected app: PlatformApplication;\n\n hasConfiguration() {\n return !!this.oidc;\n }\n\n async getConfiguration(): Promise<Configuration> {\n const [jwks, adapter] = await Promise.all([this.oidcJwks.getJwks(), this.adapters.createAdapterClass()]);\n const {issuer, jwksPath, secureKey, proxy, Accounts, ...options} = this.oidc;\n\n const configuration: Configuration = {\n interactions: {\n /* istanbul ignore next */\n url: (ctx, interaction) => `interaction/${interaction.uid}`\n },\n ...options,\n adapter,\n jwks\n };\n\n if (Accounts) {\n configuration.findAccount = (ctx, id, token) =>\n this.injector.get<OidcAccountsMethods>(Accounts)!.findAccount(id, token, (ctx.req as any).$ctx);\n }\n\n if (this.env === Env.PROD) {\n setValue(configuration, \"cookies.short.secure\", true);\n setValue(configuration, \"cookies.long.secure\", true);\n }\n\n const policy = this.getPolicy();\n if (policy) {\n setValue(configuration, \"interactions.policy\", policy);\n }\n\n const url = this.getInteractionsUrl();\n if (url) {\n setValue(configuration, \"interactions.url\", url);\n }\n\n return configuration;\n }\n\n getIssuer() {\n if (this.issuer) {\n return this.issuer;\n }\n\n // istanbul ignore next\n if (this.httpsPort) {\n return `https://localhost:${this.httpsPort}`;\n }\n\n return `http://localhost:${this.httpPort}`;\n }\n\n get(): OIDCProvider {\n return this.raw;\n }\n\n /**\n * Create a new instance of OidcProvider\n */\n async create(): Promise<void | OIDCProvider> {\n const {proxy, secureKey} = this.oidc;\n const configuration = await this.getConfiguration();\n const oidcProvider = new OIDCProvider(this.getIssuer(), configuration);\n\n if (proxy || this.env === Env.PROD) {\n // istanbul ignore next\n switch (this.platformName) {\n default:\n case \"express\":\n oidcProvider.proxy = true;\n break;\n case \"koa\":\n (this.app.rawApp as any).proxy = true;\n break;\n }\n }\n\n if (secureKey) {\n oidcProvider.app.keys = secureKey;\n }\n\n this.raw = oidcProvider;\n\n if (this.env !== Env.PROD) {\n this.allowHttpLocalhost();\n }\n\n await this.injector.emit(\"$onCreateOIDC\", this.raw);\n\n return this.raw;\n }\n\n private getInteractionsUrl() {\n const provider = this.injector.getProviders().find((provider) => provider.subType === INTERACTIONS);\n\n if (provider) {\n return (ctx: any, interaction: any) => {\n // eslint-disable-line no-unused-vars\n return provider.path.replace(/:uid/, interaction.uid);\n };\n }\n }\n\n private allowHttpLocalhost() {\n const {invalidate: orig} = (this.raw.Client as any).Schema.prototype;\n\n (this.raw.Client as any).Schema.prototype.invalidate = function invalidate(message: string, code: string) {\n if (code === \"implicit-force-https\" || code === \"implicit-forbid-localhost\") {\n return;\n }\n\n /* istanbul ignore next */\n return orig.call(this, message);\n };\n }\n\n private getPolicy() {\n const policy = interactionPolicy.base();\n const interactions = this.oidcInteractions.getInteractions();\n\n if (interactions.length) {\n interactions.forEach((provider) => {\n const {name, ...options} = provider.store.get(\"interactionOptions\");\n\n if (!policy.get(name)) {\n policy.add(\n new interactionPolicy.Prompt({\n name,\n ...options\n })\n );\n }\n\n const instance = this.injector.get(provider.token);\n\n if (instance.$onCreate) {\n instance.$onCreate(policy.get(name));\n }\n });\n }\n\n return this.injector.alter(\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AhLC;IADC,IAAA,aAAQ,EAAC,KAAK,CAAC;;yCACG;AAGnB;IADC,IAAA,aAAQ,EAAC,UAAU,CAAC;;8CACe;AAGpC;IADC,IAAA,aAAQ,EAAC,WAAW,CAAC;;+CACe;AAGrC;IADC,IAAA,aAAQ,EAAC,aAAa,EAAE,EAAE,CAAC;;4CACH;AAGzB;IADC,IAAA,aAAQ,EAAC,MAAM,CAAC;;0CACY;AAG7B;IADC,IAAA,aAAQ,EAAC,eAAe,CAAC;;kDACK;AAG/B;IADC,IAAA,WAAM,GAAE;sCACW,mBAAQ;8CAAC;AAG7B;IADC,IAAA,WAAM,GAAE;sCACmB,mCAAgB;sDAAC;AAG7C;IADC,IAAA,WAAM,GAAE;sCACW,2BAAY;8CAAC;AAGjC;IADC,IAAA,WAAM,GAAE;sCACW,oBAAe;8CAAC;AAGpC;IADC,IAAA,WAAM,GAAE;sCACM,4BAAmB;yCAAC;AAlCxB,YAAY;IADxB,IAAA,eAAU,GAAE;GACA,YAAY,CAoLxB;AApLY,oCAAY","sourcesContent":["import {PlatformApplication} from \"@tsed/common\";\nimport {Env, setValue} from \"@tsed/core\";\nimport {Constant, Inject, Injectable, InjectorService} from \"@tsed/di\";\nimport {Configuration, interactionPolicy, Provider as OIDCProvider} from \"oidc-provider\";\nimport {INTERACTIONS} from \"../constants/constants\";\nimport {OidcAccountsMethods} from \"../domain/OidcAccountsMethods\";\nimport {OidcSettings} from \"../domain/OidcSettings\";\nimport {OidcAdapters} from \"./OidcAdapters\";\nimport {OidcInteractions} from \"./OidcInteractions\";\nimport {OidcJwks} from \"./OidcJwks\";\n\n@Injectable()\nexport class OidcProvider {\n raw: OIDCProvider;\n\n @Constant(\"env\")\n protected env: Env;\n\n @Constant(\"httpPort\")\n protected httpPort: number | string;\n\n @Constant(\"httpsPort\")\n protected httpsPort: number | string;\n\n @Constant(\"oidc.issuer\", \"\")\n protected issuer: string;\n\n @Constant(\"oidc\")\n protected oidc: OidcSettings;\n\n @Constant(\"PLATFORM_NAME\")\n protected platformName: string;\n\n @Inject()\n protected oidcJwks: OidcJwks;\n\n @Inject()\n protected oidcInteractions: OidcInteractions;\n\n @Inject()\n protected adapters: OidcAdapters;\n\n @Inject()\n protected injector: InjectorService;\n\n @Inject()\n protected app: PlatformApplication;\n\n hasConfiguration() {\n return !!this.oidc;\n }\n\n async getConfiguration(): Promise<Configuration> {\n const [jwks, adapter] = await Promise.all([this.oidcJwks.getJwks(), this.adapters.createAdapterClass()]);\n const {issuer, jwksPath, secureKey, proxy, Accounts, secureCookies = this.env == Env.PROD, ...options} = this.oidc;\n\n const configuration: Configuration = {\n interactions: {\n /* istanbul ignore next */\n url: (ctx, interaction) => `interaction/${interaction.uid}`\n },\n ...options,\n adapter,\n jwks\n };\n\n if (Accounts) {\n configuration.findAccount = (ctx, id, token) => this.injector.get<OidcAccountsMethods>(Accounts)!.findAccount(id, token);\n }\n\n if (secureCookies) {\n setValue(configuration, \"cookies.short.secure\", true);\n setValue(configuration, \"cookies.long.secure\", true);\n }\n\n const policy = this.getPolicy();\n if (policy) {\n setValue(configuration, \"interactions.policy\", policy);\n }\n\n const url = this.getInteractionsUrl();\n if (url) {\n setValue(configuration, \"interactions.url\", url);\n }\n\n return configuration;\n }\n\n getIssuer() {\n if (this.issuer) {\n return this.issuer;\n }\n\n // istanbul ignore next\n if (this.httpsPort) {\n return `https://localhost:${this.httpsPort}`;\n }\n\n return `http://localhost:${this.httpPort}`;\n }\n\n get(): OIDCProvider {\n return this.raw;\n }\n\n /**\n * Create a new instance of OidcProvider\n */\n async create(): Promise<void | OIDCProvider> {\n const {proxy = this.env === Env.PROD, secureKey, allowHttpLocalhost = this.env !== Env.PROD} = this.oidc;\n const configuration = await this.getConfiguration();\n const oidcProvider = new OIDCProvider(this.getIssuer(), configuration);\n\n if (proxy) {\n // istanbul ignore next\n switch (this.platformName) {\n default:\n case \"express\":\n oidcProvider.proxy = true;\n break;\n case \"koa\":\n (this.app.rawApp as any).proxy = true;\n break;\n }\n }\n\n if (secureKey) {\n oidcProvider.app.keys = secureKey;\n }\n\n this.raw = oidcProvider;\n\n if (allowHttpLocalhost) {\n this.allowHttpLocalhost();\n }\n\n await this.injector.emit(\"$onCreateOIDC\", this.raw);\n\n return this.raw;\n }\n\n private getInteractionsUrl() {\n const provider = this.injector.getProviders().find((provider) => provider.subType === INTERACTIONS);\n\n if (provider) {\n return (ctx: any, interaction: any) => {\n // eslint-disable-line no-unused-vars\n return provider.path.replace(/:uid/, interaction.uid);\n };\n }\n }\n\n private allowHttpLocalhost() {\n const {invalidate: orig} = (this.raw.Client as any).Schema.prototype;\n\n (this.raw.Client as any).Schema.prototype.invalidate = function invalidate(message: string, code: string) {\n if (code === \"implicit-force-https\" || code === \"implicit-forbid-localhost\") {\n return;\n }\n\n /* istanbul ignore next */\n return orig.call(this, message);\n };\n }\n\n private getPolicy() {\n const policy = interactionPolicy.base();\n const interactions = this.oidcInteractions.getInteractions();\n\n if (interactions.length) {\n interactions.forEach((provider) => {\n const {name, ...options} = provider.store.get(\"interactionOptions\");\n\n if (!policy.get(name)) {\n policy.add(\n new interactionPolicy.Prompt({\n name,\n ...options\n })\n );\n }\n\n const instance = this.injector.get(provider.token);\n\n if (instance.$onCreate) {\n instance.$onCreate(policy.get(name));\n }\n });\n }\n\n return this.injector.alter(\"$alterOidcPolicy\", policy);\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OidcAccountsMethods.js","sourceRoot":"","sources":["../../../src/domain/OidcAccountsMethods.ts"],"names":[],"mappings":"","sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"OidcAccountsMethods.js","sourceRoot":"","sources":["../../../src/domain/OidcAccountsMethods.ts"],"names":[],"mappings":"","sourcesContent":["import {Provider, Account} from \"oidc-provider\";\n\nexport type AuthorizationCode = InstanceType<Provider[\"AuthorizationCode\"]>;\nexport type AccessToken = InstanceType<Provider[\"AccessToken\"]>;\nexport type DeviceCode = InstanceType<Provider[\"DeviceCode\"]>;\nexport type BackchannelAuthenticationRequest = InstanceType<Provider[\"BackchannelAuthenticationRequest\"]>;\n\nexport interface OidcAccountsMethods {\n findAccount(\n id: string,\n token: AuthorizationCode | AccessToken | DeviceCode | BackchannelAuthenticationRequest | undefined\n ): Promise<Account | undefined>;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
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"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OidcSettings.js","sourceRoot":"","sources":["../../../src/domain/OidcSettings.ts"],"names":[],"mappings":"","sourcesContent":["import {Type} from \"@tsed/core\";\nimport {JwksKeyParameters} from \"@tsed/jwks\";\nimport {Configuration} from \"oidc-provider\";\nimport {OidcAccountsMethods} from \"./OidcAccountsMethods\";\n\nexport interface OidcSettings extends Configuration {\n /**\n * Path on which the oidc-provider instance is mounted.\n */\n path?: string;\n /**\n * Issuer URI. By default Ts.ED create issuer with http://localhost:${httpPort}\n */\n issuer?: string;\n /**\n * Path to store jwks keys.\n */\n jwksPath?: string;\n /**\n * Generate jwks from given certificates\n */\n certificates?: JwksKeyParameters[];\n /**\n * Secure keys.\n */\n secureKey?: string[];\n /**\n * Enable proxy.\n */\n proxy?: boolean;\n /**\n *
|
|
1
|
+
{"version":3,"file":"OidcSettings.js","sourceRoot":"","sources":["../../../src/domain/OidcSettings.ts"],"names":[],"mappings":"","sourcesContent":["import {Type} from \"@tsed/core\";\nimport {JwksKeyParameters} from \"@tsed/jwks\";\nimport {Configuration} from \"oidc-provider\";\nimport {OidcAccountsMethods} from \"./OidcAccountsMethods\";\n\nexport interface OidcSettings extends Configuration {\n /**\n * force the secure cookie. By default, in dev mode it's disabled and in production it's enabled.\n */\n secureCookies?: boolean;\n /**\n * Path on which the oidc-provider instance is mounted.\n */\n path?: string;\n /**\n * Issuer URI. By default, Ts.ED create issuer with http://localhost:${httpPort}\n */\n issuer?: string;\n /**\n * Path to store jwks keys.\n */\n jwksPath?: string;\n /**\n * Generate jwks from given certificates\n */\n certificates?: JwksKeyParameters[];\n /**\n * Secure keys.\n */\n secureKey?: string[];\n /**\n * Enable proxy.\n */\n proxy?: boolean;\n /**\n * Allow redirect_uri on HTTP protocol and localhost domain.\n */\n allowHttpLocalhost?: boolean;\n /**\n * Injectable service to manage accounts.\n */\n Accounts?: Type<OidcAccountsMethods>;\n}\n\ndeclare global {\n namespace TsED {\n interface Configuration {\n oidc: OidcSettings;\n }\n }\n}\n"]}
|
package/lib/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"]}
|
|
@@ -1,38 +1,16 @@
|
|
|
1
|
-
import { __decorate, __metadata
|
|
2
|
-
import {
|
|
3
|
-
import { INTERACTION_CONTEXT, INTERACTION_DETAILS, INTERACTION_GRANT_ID, INTERACTION_PARAMS, INTERACTION_PROMPT, INTERACTION_SESSION, INTERACTION_UID } from "../constants/constants.js";
|
|
1
|
+
import { __decorate, __metadata } from "tslib";
|
|
2
|
+
import { Inject, Middleware } from "@tsed/common";
|
|
4
3
|
import { OidcInteractionContext } from "../services/OidcInteractionContext.js";
|
|
5
|
-
import { OidcInteractions } from "../services/OidcInteractions.js";
|
|
6
4
|
let OidcInteractionMiddleware = class OidcInteractionMiddleware {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const oidcInteraction = this.injector.invoke(OidcInteractionContext, context.container);
|
|
11
|
-
const interactionDetails = await oidcInteraction.interactionDetails();
|
|
12
|
-
const { uid, prompt, params, session, grantId } = interactionDetails;
|
|
13
|
-
context.set(INTERACTION_CONTEXT, oidcInteraction);
|
|
14
|
-
context.set(INTERACTION_DETAILS, interactionDetails);
|
|
15
|
-
context.set(INTERACTION_UID, uid);
|
|
16
|
-
context.set(INTERACTION_PROMPT, prompt);
|
|
17
|
-
context.set(INTERACTION_PARAMS, params);
|
|
18
|
-
context.set(INTERACTION_GRANT_ID, grantId);
|
|
19
|
-
context.set(INTERACTION_SESSION, session);
|
|
5
|
+
oidcInteractionContext;
|
|
6
|
+
async use() {
|
|
7
|
+
await this.oidcInteractionContext.interactionDetails();
|
|
20
8
|
}
|
|
21
9
|
};
|
|
22
10
|
__decorate([
|
|
23
11
|
Inject(),
|
|
24
|
-
__metadata("design:type",
|
|
25
|
-
], OidcInteractionMiddleware.prototype, "
|
|
26
|
-
__decorate([
|
|
27
|
-
Inject(),
|
|
28
|
-
__metadata("design:type", InjectorService)
|
|
29
|
-
], OidcInteractionMiddleware.prototype, "injector", void 0);
|
|
30
|
-
__decorate([
|
|
31
|
-
__param(0, Context()),
|
|
32
|
-
__metadata("design:type", Function),
|
|
33
|
-
__metadata("design:paramtypes", [Object]),
|
|
34
|
-
__metadata("design:returntype", Promise)
|
|
35
|
-
], OidcInteractionMiddleware.prototype, "use", null);
|
|
12
|
+
__metadata("design:type", OidcInteractionContext)
|
|
13
|
+
], OidcInteractionMiddleware.prototype, "oidcInteractionContext", void 0);
|
|
36
14
|
OidcInteractionMiddleware = __decorate([
|
|
37
15
|
Middleware()
|
|
38
16
|
], OidcInteractionMiddleware);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OidcInteractionMiddleware.js","sourceRoot":"","sources":["../../../src/middlewares/OidcInteractionMiddleware.ts"],"names":[],"mappings":";AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"OidcInteractionMiddleware.js","sourceRoot":"","sources":["../../../src/middlewares/OidcInteractionMiddleware.ts"],"names":[],"mappings":";AAAA,OAAO,EAAU,MAAM,EAAmB,UAAU,EAAC,MAAM,cAAc,CAAC;AAU1E,OAAO,EAAC,sBAAsB,EAAC,MAAM,oCAAoC,CAAC;AAI1E,IAAa,yBAAyB,GAAtC,MAAa,yBAAyB;IAE1B,sBAAsB,CAAyB;IAEzD,KAAK,CAAC,GAAG;QACP,MAAM,IAAI,CAAC,sBAAsB,CAAC,kBAAkB,EAAE,CAAC;IACzD,CAAC;CACF,CAAA;AALC;IADC,MAAM,EAAE;8BACyB,sBAAsB;yEAAC;AAF9C,yBAAyB;IADrC,UAAU,EAAE;GACA,yBAAyB,CAOrC;SAPY,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 oidcInteractionContext: OidcInteractionContext;\n\n async use() {\n await this.oidcInteractionContext.interactionDetails();\n }\n}\n"]}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { __decorate, __metadata } from "tslib";
|
|
2
|
-
import { Constant,
|
|
2
|
+
import { Constant, InjectContext, PlatformContext } 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 { INTERACTION_CONTEXT, INTERACTION_DETAILS, INTERACTION_GRANT_ID, INTERACTION_PARAMS, INTERACTION_PROMPT, INTERACTION_SESSION, INTERACTION_UID } from "../constants/constants.js";
|
|
7
|
+
import { OidcBadInteractionName } from "../domain/OidcBadInteractionName.js";
|
|
5
8
|
import { debug } from "../utils/debug.js";
|
|
6
9
|
import { OidcInteractions } from "./OidcInteractions.js";
|
|
7
10
|
import { OidcProvider } from "./OidcProvider.js";
|
|
@@ -10,7 +13,9 @@ let OidcInteractionContext = class OidcInteractionContext {
|
|
|
10
13
|
oidcProvider;
|
|
11
14
|
oidcInteractions;
|
|
12
15
|
$ctx;
|
|
13
|
-
raw
|
|
16
|
+
get raw() {
|
|
17
|
+
return this.$ctx.get(INTERACTION_DETAILS);
|
|
18
|
+
}
|
|
14
19
|
get session() {
|
|
15
20
|
return this.raw.session;
|
|
16
21
|
}
|
|
@@ -33,8 +38,16 @@ let OidcInteractionContext = class OidcInteractionContext {
|
|
|
33
38
|
}
|
|
34
39
|
}
|
|
35
40
|
async interactionDetails() {
|
|
36
|
-
|
|
37
|
-
|
|
41
|
+
const raw = await this.oidcProvider.get().interactionDetails(this.$ctx.getReq(), this.$ctx.getRes());
|
|
42
|
+
const { uid, prompt, params, session, grantId } = raw;
|
|
43
|
+
this.$ctx.set(INTERACTION_CONTEXT, this);
|
|
44
|
+
this.$ctx.set(INTERACTION_DETAILS, raw);
|
|
45
|
+
this.$ctx.set(INTERACTION_UID, uid);
|
|
46
|
+
this.$ctx.set(INTERACTION_PROMPT, prompt);
|
|
47
|
+
this.$ctx.set(INTERACTION_PARAMS, params);
|
|
48
|
+
this.$ctx.set(INTERACTION_GRANT_ID, grantId);
|
|
49
|
+
this.$ctx.set(INTERACTION_SESSION, session);
|
|
50
|
+
return raw;
|
|
38
51
|
}
|
|
39
52
|
async interactionFinished(result, options = { mergeWithLastSubmission: false }) {
|
|
40
53
|
return this.oidcProvider.get().interactionFinished(this.$ctx.getReq(), this.$ctx.getRes(), result, options);
|
|
@@ -42,6 +55,21 @@ let OidcInteractionContext = class OidcInteractionContext {
|
|
|
42
55
|
async interactionResult(result, options = { mergeWithLastSubmission: false }) {
|
|
43
56
|
return this.oidcProvider.get().interactionResult(this.$ctx.getReq(), this.$ctx.getRes(), result, options);
|
|
44
57
|
}
|
|
58
|
+
async interactionPrompt(options) {
|
|
59
|
+
const client = await this.findClient();
|
|
60
|
+
return {
|
|
61
|
+
client,
|
|
62
|
+
uid: this.uid,
|
|
63
|
+
grantId: this.grantId,
|
|
64
|
+
details: this.prompt.details,
|
|
65
|
+
params: {
|
|
66
|
+
...this.params,
|
|
67
|
+
...options.params
|
|
68
|
+
},
|
|
69
|
+
...options,
|
|
70
|
+
...this.debug()
|
|
71
|
+
};
|
|
72
|
+
}
|
|
45
73
|
async render(view, result) {
|
|
46
74
|
return this.$ctx.response.render(view, result);
|
|
47
75
|
}
|
|
@@ -49,7 +77,8 @@ let OidcInteractionContext = class OidcInteractionContext {
|
|
|
49
77
|
return this.raw.save(ttl);
|
|
50
78
|
}
|
|
51
79
|
async findClient(clientId = this.params.client_id) {
|
|
52
|
-
|
|
80
|
+
const key = `$client:${clientId}`;
|
|
81
|
+
return this.$ctx.cacheAsync(key, () => this.oidcProvider.get().Client.find(clientId));
|
|
53
82
|
}
|
|
54
83
|
async findAccount(sub, token) {
|
|
55
84
|
if (!sub && this.session) {
|
|
@@ -58,7 +87,10 @@ let OidcInteractionContext = class OidcInteractionContext {
|
|
|
58
87
|
if (!sub) {
|
|
59
88
|
return;
|
|
60
89
|
}
|
|
61
|
-
|
|
90
|
+
const key = `$account:${sub}`;
|
|
91
|
+
return this.$ctx.cacheAsync(key, (() => {
|
|
92
|
+
return this.oidcProvider.get().Account.findAccount(undefined, sub, token);
|
|
93
|
+
}));
|
|
62
94
|
}
|
|
63
95
|
async getGrant() {
|
|
64
96
|
const { Grant } = this.oidcProvider.get();
|
|
@@ -72,6 +104,17 @@ let OidcInteractionContext = class OidcInteractionContext {
|
|
|
72
104
|
clientId: this.params.client_id
|
|
73
105
|
});
|
|
74
106
|
}
|
|
107
|
+
checkInteractionName(name) {
|
|
108
|
+
if (this.prompt.name !== name) {
|
|
109
|
+
throw new OidcBadInteractionName("Bad interaction name");
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
async checkClientId(clientId = this.params.client_id) {
|
|
113
|
+
const client = await this.findClient(clientId);
|
|
114
|
+
if (!client) {
|
|
115
|
+
throw new Unauthorized(`Unknown client_id ${clientId}`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
75
118
|
debug(obj) {
|
|
76
119
|
/* istanbul ignore next */
|
|
77
120
|
if (this.env === Env.PROD) {
|
|
@@ -102,12 +145,11 @@ __decorate([
|
|
|
102
145
|
__metadata("design:type", OidcInteractions)
|
|
103
146
|
], OidcInteractionContext.prototype, "oidcInteractions", void 0);
|
|
104
147
|
__decorate([
|
|
105
|
-
|
|
148
|
+
InjectContext(),
|
|
106
149
|
__metadata("design:type", PlatformContext)
|
|
107
150
|
], OidcInteractionContext.prototype, "$ctx", void 0);
|
|
108
151
|
OidcInteractionContext = __decorate([
|
|
109
|
-
Injectable()
|
|
110
|
-
Scope(ProviderScope.REQUEST)
|
|
152
|
+
Injectable()
|
|
111
153
|
], OidcInteractionContext);
|
|
112
154
|
export { OidcInteractionContext };
|
|
113
155
|
//# sourceMappingURL=OidcInteractionContext.js.map
|
|
@@ -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,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;IAGC,YAAY,CAAe;IAG3B,gBAAgB,CAAmB;IAGnC,IAAI,CAAkB;IAEtB,GAAG,CAAkB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AI,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;SACzE;QAED,OAAO,IAAI,KAAK,CAAC;YACf,SAAS,EAAE,IAAI,CAAC,OAAO,EAAE,SAAS;YAClC,QAAQ,EAAE,IAAI,CAAC,MAAM,CAAC,SAAS;SAChC,CAAC,CAAC;IACL,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;AAhHC;IADC,QAAQ,CAAC,KAAK,CAAC;;mDACP;AAGT;IADC,MAAM,EAAE;8BACe,YAAY;4DAAC;AAGrC;IADC,MAAM,EAAE;8BACmB,gBAAgB;gEAAC;AAG7C;IADC,MAAM,EAAE;8BACO,eAAe;oDAAC;AAXrB,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 $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 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 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,aAAa,EAAE,eAAe,EAAC,MAAM,cAAc,CAAC;AACtE,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;AAE9C,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,EACpB,kBAAkB,EAClB,kBAAkB,EAClB,mBAAmB,EACnB,eAAe,EAChB,MAAM,wBAAwB,CAAC;AAGhC,OAAO,EAAC,sBAAsB,EAAC,MAAM,kCAAkC,CAAC;AAGxE,OAAO,EAAC,KAAK,EAAC,MAAM,gBAAgB,CAAC;AACrC,OAAO,EAAC,gBAAgB,EAAC,MAAM,oBAAoB,CAAC;AACpD,OAA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AC,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;AAjKC;IADC,QAAQ,CAAC,KAAK,CAAC;;mDACP;AAGT;IADC,MAAM,EAAE;8BACe,YAAY;4DAAC;AAGrC;IADC,MAAM,EAAE;8BACmB,gBAAgB;gEAAC;AAG7C;IADC,aAAa,EAAE;8BACA,eAAe;oDAAC;AAXrB,sBAAsB;IADlC,UAAU,EAAE;GACA,sBAAsB,CAmKlC;SAnKY,sBAAsB","sourcesContent":["import {Constant, InjectContext, PlatformContext} from \"@tsed/common\";\nimport {Env} from \"@tsed/core\";\nimport {Inject, Injectable} from \"@tsed/di\";\nimport {Unauthorized} from \"@tsed/exceptions\";\nimport {Account, InteractionResults, PromptDetail, Provider} from \"oidc-provider\";\nimport {\n INTERACTION_CONTEXT,\n INTERACTION_DETAILS,\n INTERACTION_GRANT_ID,\n INTERACTION_PARAMS,\n INTERACTION_PROMPT,\n INTERACTION_SESSION,\n INTERACTION_UID\n} from \"../constants/constants\";\nimport {OidcSession} from \"../decorators/oidcSession\";\nimport {OidcClient} from \"../domain/interfaces\";\nimport {OidcBadInteractionName} from \"../domain/OidcBadInteractionName\";\nimport {OidcInteraction} from \"../domain/OidcInteraction\";\nimport {OidcInteractionPromptProps} from \"../domain/OidcInteractionPromptProps\";\nimport {debug} from \"../utils/debug\";\nimport {OidcInteractions} from \"./OidcInteractions\";\nimport {OidcProvider} from \"./OidcProvider\";\n\n@Injectable()\nexport class OidcInteractionContext {\n @Constant(\"env\")\n env: Env;\n\n @Inject()\n protected oidcProvider: OidcProvider;\n\n @Inject()\n protected oidcInteractions: OidcInteractions;\n\n @InjectContext()\n protected $ctx: PlatformContext;\n\n get raw(): OidcInteraction {\n return this.$ctx.get(INTERACTION_DETAILS)!;\n }\n\n get session(): OidcSession | undefined {\n return this.raw.session as any;\n }\n\n get prompt(): PromptDetail {\n return this.raw.prompt;\n }\n\n get params(): Record<string, any> {\n return this.raw.params;\n }\n\n get uid(): string {\n return this.raw.uid;\n }\n\n get grantId(): string {\n return (this.raw as any).grantId;\n }\n\n async runInteraction(name: string = this.prompt.name) {\n const handler = this.oidcInteractions.getInteractionHandler(name);\n\n if (handler) {\n await handler(this.$ctx);\n }\n }\n\n async interactionDetails(): Promise<OidcInteraction> {\n const raw = await this.oidcProvider.get().interactionDetails(this.$ctx.getReq(), this.$ctx.getRes());\n\n const {uid, prompt, params, session, grantId} = raw as any;\n\n this.$ctx.set(INTERACTION_CONTEXT, this);\n this.$ctx.set(INTERACTION_DETAILS, raw);\n this.$ctx.set(INTERACTION_UID, uid);\n this.$ctx.set(INTERACTION_PROMPT, prompt);\n this.$ctx.set(INTERACTION_PARAMS, params);\n this.$ctx.set(INTERACTION_GRANT_ID, grantId);\n this.$ctx.set(INTERACTION_SESSION, session);\n\n return raw;\n }\n\n async interactionFinished(result: InteractionResults, options: {mergeWithLastSubmission?: boolean} = {mergeWithLastSubmission: false}) {\n return this.oidcProvider.get().interactionFinished(this.$ctx.getReq(), this.$ctx.getRes(), result, options);\n }\n\n async interactionResult(result: InteractionResults, options: {mergeWithLastSubmission?: boolean} = {mergeWithLastSubmission: false}) {\n return this.oidcProvider.get().interactionResult(this.$ctx.getReq(), this.$ctx.getRes(), result, options);\n }\n\n async interactionPrompt(options: Record<string, any>): Promise<OidcInteractionPromptProps> {\n const client = await this.findClient();\n\n return {\n client,\n uid: this.uid,\n grantId: this.grantId,\n details: this.prompt.details,\n params: {\n ...this.params,\n ...options.params\n },\n ...options,\n ...this.debug()\n };\n }\n\n async render(view: string, result: any): Promise<string> {\n return this.$ctx.response.render(view, result);\n }\n\n async save(ttl: number): Promise<string> {\n return this.raw.save(ttl);\n }\n\n async findClient(clientId: string = this.params.client_id): Promise<OidcClient | undefined> {\n const key = `$client:${clientId}`;\n\n return this.$ctx.cacheAsync(key, () => this.oidcProvider.get().Client.find(clientId));\n }\n\n async findAccount(sub?: string, token?: any): Promise<Account | undefined> {\n if (!sub && this.session) {\n sub = this.session?.accountId as any;\n }\n\n if (!sub) {\n return;\n }\n\n const key = `$account:${sub}`;\n\n return this.$ctx.cacheAsync<Account | undefined>(key, (() => {\n return this.oidcProvider.get().Account.findAccount(undefined as any, sub!, token);\n }) as any);\n }\n\n async getGrant(): Promise<InstanceType<Provider[\"Grant\"]>> {\n const {Grant} = this.oidcProvider.get() as any;\n\n if (this.grantId) {\n // we'll be modifying existing grant in existing session\n // @ts-ignore\n return await (this.oidcProvider.get().find || Grant.find)(this.grantId);\n }\n\n return new Grant({\n accountId: this.session?.accountId,\n clientId: this.params.client_id\n });\n }\n\n checkInteractionName(name: string) {\n if (this.prompt.name !== name) {\n throw new OidcBadInteractionName(\"Bad interaction name\");\n }\n }\n\n async checkClientId(clientId = this.params.client_id) {\n const client = await this.findClient(clientId);\n\n if (!client) {\n throw new Unauthorized(`Unknown client_id ${clientId}`);\n }\n }\n\n debug(obj?: any): any {\n /* istanbul ignore next */\n if (this.env === Env.PROD) {\n return {session: undefined, dbg: {params: undefined, prompt: undefined}};\n }\n\n if (obj) {\n return debug(obj);\n }\n\n return {\n session: this.session ? this.debug(this.session) : undefined,\n dbg: {\n params: this.debug(this.params),\n prompt: this.debug(this.prompt)\n }\n };\n }\n}\n"]}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { __decorate, __metadata } from "tslib";
|
|
2
|
+
import { PlatformApplication } from "@tsed/common";
|
|
2
3
|
import { Env, setValue } from "@tsed/core";
|
|
3
4
|
import { Constant, Inject, Injectable, InjectorService } from "@tsed/di";
|
|
4
|
-
import { Provider as OIDCProvider
|
|
5
|
+
import { interactionPolicy, Provider as OIDCProvider } from "oidc-provider";
|
|
5
6
|
import { INTERACTIONS } from "../constants/constants.js";
|
|
6
7
|
import { OidcAdapters } from "./OidcAdapters.js";
|
|
7
8
|
import { OidcInteractions } from "./OidcInteractions.js";
|
|
8
9
|
import { OidcJwks } from "./OidcJwks.js";
|
|
9
|
-
import { PlatformApplication } from "@tsed/common";
|
|
10
10
|
let OidcProvider = class OidcProvider {
|
|
11
11
|
raw;
|
|
12
12
|
env;
|
|
@@ -25,7 +25,7 @@ let OidcProvider = class OidcProvider {
|
|
|
25
25
|
}
|
|
26
26
|
async getConfiguration() {
|
|
27
27
|
const [jwks, adapter] = await Promise.all([this.oidcJwks.getJwks(), this.adapters.createAdapterClass()]);
|
|
28
|
-
const { issuer, jwksPath, secureKey, proxy, Accounts, ...options } = this.oidc;
|
|
28
|
+
const { issuer, jwksPath, secureKey, proxy, Accounts, secureCookies = this.env == Env.PROD, ...options } = this.oidc;
|
|
29
29
|
const configuration = {
|
|
30
30
|
interactions: {
|
|
31
31
|
/* istanbul ignore next */
|
|
@@ -36,9 +36,9 @@ let OidcProvider = class OidcProvider {
|
|
|
36
36
|
jwks
|
|
37
37
|
};
|
|
38
38
|
if (Accounts) {
|
|
39
|
-
configuration.findAccount = (ctx, id, token) => this.injector.get(Accounts).findAccount(id, token
|
|
39
|
+
configuration.findAccount = (ctx, id, token) => this.injector.get(Accounts).findAccount(id, token);
|
|
40
40
|
}
|
|
41
|
-
if (
|
|
41
|
+
if (secureCookies) {
|
|
42
42
|
setValue(configuration, "cookies.short.secure", true);
|
|
43
43
|
setValue(configuration, "cookies.long.secure", true);
|
|
44
44
|
}
|
|
@@ -69,10 +69,10 @@ let OidcProvider = class OidcProvider {
|
|
|
69
69
|
* Create a new instance of OidcProvider
|
|
70
70
|
*/
|
|
71
71
|
async create() {
|
|
72
|
-
const { proxy, secureKey } = this.oidc;
|
|
72
|
+
const { proxy = this.env === Env.PROD, secureKey, allowHttpLocalhost = this.env !== Env.PROD } = this.oidc;
|
|
73
73
|
const configuration = await this.getConfiguration();
|
|
74
74
|
const oidcProvider = new OIDCProvider(this.getIssuer(), configuration);
|
|
75
|
-
if (proxy
|
|
75
|
+
if (proxy) {
|
|
76
76
|
// istanbul ignore next
|
|
77
77
|
switch (this.platformName) {
|
|
78
78
|
default:
|
|
@@ -88,7 +88,7 @@ let OidcProvider = class OidcProvider {
|
|
|
88
88
|
oidcProvider.app.keys = secureKey;
|
|
89
89
|
}
|
|
90
90
|
this.raw = oidcProvider;
|
|
91
|
-
if (
|
|
91
|
+
if (allowHttpLocalhost) {
|
|
92
92
|
this.allowHttpLocalhost();
|
|
93
93
|
}
|
|
94
94
|
await this.injector.emit("$onCreateOIDC", this.raw);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OidcProvider.js","sourceRoot":"","sources":["../../../src/services/OidcProvider.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,GAAG,EAAE,QAAQ,EAAC,MAAM,YAAY,CAAC;AACzC,OAAO,EAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,eAAe,EAAC,MAAM,UAAU,CAAC;AACvE,OAAO,EAAC,QAAQ,IAAI,YAAY,EAAiB,iBAAiB,EAAC,MAAM,eAAe,CAAC;AACzF,OAAO,EAAC,YAAY,EAAC,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAC,gBAAgB,EAAC,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAC,QAAQ,EAAC,MAAM,YAAY,CAAC;AACpC,OAAO,EAAC,mBAAmB,EAAC,MAAM,cAAc,CAAC;AAKjD,IAAa,YAAY,GAAzB,MAAa,YAAY;IACvB,GAAG,CAAe;IAGR,GAAG,CAAM;IAGT,QAAQ,CAAkB;IAG1B,SAAS,CAAkB;IAG3B,MAAM,CAAS;IAGf,IAAI,CAAe;IAGn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W,eAAe;8CAAC;AAGpC;IADC,MAAM,EAAE;8BACM,mBAAmB;yCAAC;AAlCxB,YAAY;IADxB,UAAU,EAAE;GACA,YAAY,CAqLxB;SArLY,YAAY","sourcesContent":["import {Env, setValue} from \"@tsed/core\";\nimport {Constant, Inject, Injectable, InjectorService} from \"@tsed/di\";\nimport {Provider as OIDCProvider, Configuration, interactionPolicy} from \"oidc-provider\";\nimport {INTERACTIONS} from \"../constants/constants\";\nimport {OidcAdapters} from \"./OidcAdapters\";\nimport {OidcInteractions} from \"./OidcInteractions\";\nimport {OidcJwks} from \"./OidcJwks\";\nimport {PlatformApplication} from \"@tsed/common\";\nimport {OidcSettings} from \"../domain/OidcSettings\";\nimport {OidcAccountsMethods} from \"../domain/OidcAccountsMethods\";\n\n@Injectable()\nexport class OidcProvider {\n raw: OIDCProvider;\n\n @Constant(\"env\")\n protected env: Env;\n\n @Constant(\"httpPort\")\n protected httpPort: number | string;\n\n @Constant(\"httpsPort\")\n protected httpsPort: number | string;\n\n @Constant(\"oidc.issuer\", \"\")\n protected issuer: string;\n\n @Constant(\"oidc\")\n protected oidc: OidcSettings;\n\n @Constant(\"PLATFORM_NAME\")\n protected platformName: string;\n\n @Inject()\n protected oidcJwks: OidcJwks;\n\n @Inject()\n protected oidcInteractions: OidcInteractions;\n\n @Inject()\n protected adapters: OidcAdapters;\n\n @Inject()\n protected injector: InjectorService;\n\n @Inject()\n protected app: PlatformApplication;\n\n hasConfiguration() {\n return !!this.oidc;\n }\n\n async getConfiguration(): Promise<Configuration> {\n const [jwks, adapter] = await Promise.all([this.oidcJwks.getJwks(), this.adapters.createAdapterClass()]);\n const {issuer, jwksPath, secureKey, proxy, Accounts, ...options} = this.oidc;\n\n const configuration: Configuration = {\n interactions: {\n /* istanbul ignore next */\n url: (ctx, interaction) => `interaction/${interaction.uid}`\n },\n ...options,\n adapter,\n jwks\n };\n\n if (Accounts) {\n configuration.findAccount = (ctx, id, token) =>\n this.injector.get<OidcAccountsMethods>(Accounts)!.findAccount(id, token, (ctx.req as any).$ctx);\n }\n\n if (this.env === Env.PROD) {\n setValue(configuration, \"cookies.short.secure\", true);\n setValue(configuration, \"cookies.long.secure\", true);\n }\n\n const policy = this.getPolicy();\n if (policy) {\n setValue(configuration, \"interactions.policy\", policy);\n }\n\n const url = this.getInteractionsUrl();\n if (url) {\n setValue(configuration, \"interactions.url\", url);\n }\n\n return configuration;\n }\n\n getIssuer() {\n if (this.issuer) {\n return this.issuer;\n }\n\n // istanbul ignore next\n if (this.httpsPort) {\n return `https://localhost:${this.httpsPort}`;\n }\n\n return `http://localhost:${this.httpPort}`;\n }\n\n get(): OIDCProvider {\n return this.raw;\n }\n\n /**\n * Create a new instance of OidcProvider\n */\n async create(): Promise<void | OIDCProvider> {\n const {proxy, secureKey} = this.oidc;\n const configuration = await this.getConfiguration();\n const oidcProvider = new OIDCProvider(this.getIssuer(), configuration);\n\n if (proxy || this.env === Env.PROD) {\n // istanbul ignore next\n switch (this.platformName) {\n default:\n case \"express\":\n oidcProvider.proxy = true;\n break;\n case \"koa\":\n (this.app.rawApp as any).proxy = true;\n break;\n }\n }\n\n if (secureKey) {\n oidcProvider.app.keys = secureKey;\n }\n\n this.raw = oidcProvider;\n\n if (this.env !== Env.PROD) {\n this.allowHttpLocalhost();\n }\n\n await this.injector.emit(\"$onCreateOIDC\", this.raw);\n\n return this.raw;\n }\n\n private getInteractionsUrl() {\n const provider = this.injector.getProviders().find((provider) => provider.subType === INTERACTIONS);\n\n if (provider) {\n return (ctx: any, interaction: any) => {\n // eslint-disable-line no-unused-vars\n return provider.path.replace(/:uid/, interaction.uid);\n };\n }\n }\n\n private allowHttpLocalhost() {\n const {invalidate: orig} = (this.raw.Client as any).Schema.prototype;\n\n (this.raw.Client as any).Schema.prototype.invalidate = function invalidate(message: string, code: string) {\n if (code === \"implicit-force-https\" || code === \"implicit-forbid-localhost\") {\n return;\n }\n\n /* istanbul ignore next */\n return orig.call(this, message);\n };\n }\n\n private getPolicy() {\n const policy = interactionPolicy.base();\n const interactions = this.oidcInteractions.getInteractions();\n\n if (interactions.length) {\n interactions.forEach((provider) => {\n const {name, ...options} = provider.store.get(\"interactionOptions\");\n\n if (!policy.get(name)) {\n policy.add(\n new interactionPolicy.Prompt({\n name,\n ...options\n })\n );\n }\n\n const instance = this.injector.get(provider.token);\n\n if (instance.$onCreate) {\n instance.$onCreate(policy.get(name));\n }\n });\n }\n\n return this.injector.alter(\"$alterOidcPolicy\", policy);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"OidcProvider.js","sourceRoot":"","sources":["../../../src/services/OidcProvider.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,mBAAmB,EAAC,MAAM,cAAc,CAAC;AACjD,OAAO,EAAC,GAAG,EAAE,QAAQ,EAAC,MAAM,YAAY,CAAC;AACzC,OAAO,EAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,eAAe,EAAC,MAAM,UAAU,CAAC;AACvE,OAAO,EAAgB,iBAAiB,EAAE,QAAQ,IAAI,YAAY,EAAC,MAAM,eAAe,CAAC;AACzF,OAAO,EAAC,YAAY,EAAC,MAAM,wBAAwB,CAAC;AAGpD,OAAO,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAC,gBAAgB,EAAC,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAC,QAAQ,EAAC,MAAM,YAAY,CAAC;AAGpC,IAAa,YAAY,GAAzB,MAAa,YAAY;IACvB,GAAG,CAAe;IAGR,GAAG,CAAM;IAGT,QAAQ,CAAkB;IAG1B,SAAS,CAAkB;IAG3B,MAAM,CAAS;IAGf,IAAI,CAAe;IAGnB,YAAY,CAAS;IAGrB,QAAQ,CAAW;IAGnB,gBAAgB,CAAmB;IAGnC,QAAQ,CAAe;IAGvB,QAAQ,CAAkB;IAG1B,GAAG,CAAsB;IAEnC,gBAAgB;QACd,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;IACrB,CAAC;IAED,KAAK,C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port {Constant, Inject, Injectable, InjectorService} from \"@tsed/di\";\nimport {Configuration, interactionPolicy, Provider as OIDCProvider} from \"oidc-provider\";\nimport {INTERACTIONS} from \"../constants/constants\";\nimport {OidcAccountsMethods} from \"../domain/OidcAccountsMethods\";\nimport {OidcSettings} from \"../domain/OidcSettings\";\nimport {OidcAdapters} from \"./OidcAdapters\";\nimport {OidcInteractions} from \"./OidcInteractions\";\nimport {OidcJwks} from \"./OidcJwks\";\n\n@Injectable()\nexport class OidcProvider {\n raw: OIDCProvider;\n\n @Constant(\"env\")\n protected env: Env;\n\n @Constant(\"httpPort\")\n protected httpPort: number | string;\n\n @Constant(\"httpsPort\")\n protected httpsPort: number | string;\n\n @Constant(\"oidc.issuer\", \"\")\n protected issuer: string;\n\n @Constant(\"oidc\")\n protected oidc: OidcSettings;\n\n @Constant(\"PLATFORM_NAME\")\n protected platformName: string;\n\n @Inject()\n protected oidcJwks: OidcJwks;\n\n @Inject()\n protected oidcInteractions: OidcInteractions;\n\n @Inject()\n protected adapters: OidcAdapters;\n\n @Inject()\n protected injector: InjectorService;\n\n @Inject()\n protected app: PlatformApplication;\n\n hasConfiguration() {\n return !!this.oidc;\n }\n\n async getConfiguration(): Promise<Configuration> {\n const [jwks, adapter] = await Promise.all([this.oidcJwks.getJwks(), this.adapters.createAdapterClass()]);\n const {issuer, jwksPath, secureKey, proxy, Accounts, secureCookies = this.env == Env.PROD, ...options} = this.oidc;\n\n const configuration: Configuration = {\n interactions: {\n /* istanbul ignore next */\n url: (ctx, interaction) => `interaction/${interaction.uid}`\n },\n ...options,\n adapter,\n jwks\n };\n\n if (Accounts) {\n configuration.findAccount = (ctx, id, token) => this.injector.get<OidcAccountsMethods>(Accounts)!.findAccount(id, token);\n }\n\n if (secureCookies) {\n setValue(configuration, \"cookies.short.secure\", true);\n setValue(configuration, \"cookies.long.secure\", true);\n }\n\n const policy = this.getPolicy();\n if (policy) {\n setValue(configuration, \"interactions.policy\", policy);\n }\n\n const url = this.getInteractionsUrl();\n if (url) {\n setValue(configuration, \"interactions.url\", url);\n }\n\n return configuration;\n }\n\n getIssuer() {\n if (this.issuer) {\n return this.issuer;\n }\n\n // istanbul ignore next\n if (this.httpsPort) {\n return `https://localhost:${this.httpsPort}`;\n }\n\n return `http://localhost:${this.httpPort}`;\n }\n\n get(): OIDCProvider {\n return this.raw;\n }\n\n /**\n * Create a new instance of OidcProvider\n */\n async create(): Promise<void | OIDCProvider> {\n const {proxy = this.env === Env.PROD, secureKey, allowHttpLocalhost = this.env !== Env.PROD} = this.oidc;\n const configuration = await this.getConfiguration();\n const oidcProvider = new OIDCProvider(this.getIssuer(), configuration);\n\n if (proxy) {\n // istanbul ignore next\n switch (this.platformName) {\n default:\n case \"express\":\n oidcProvider.proxy = true;\n break;\n case \"koa\":\n (this.app.rawApp as any).proxy = true;\n break;\n }\n }\n\n if (secureKey) {\n oidcProvider.app.keys = secureKey;\n }\n\n this.raw = oidcProvider;\n\n if (allowHttpLocalhost) {\n this.allowHttpLocalhost();\n }\n\n await this.injector.emit(\"$onCreateOIDC\", this.raw);\n\n return this.raw;\n }\n\n private getInteractionsUrl() {\n const provider = this.injector.getProviders().find((provider) => provider.subType === INTERACTIONS);\n\n if (provider) {\n return (ctx: any, interaction: any) => {\n // eslint-disable-line no-unused-vars\n return provider.path.replace(/:uid/, interaction.uid);\n };\n }\n }\n\n private allowHttpLocalhost() {\n const {invalidate: orig} = (this.raw.Client as any).Schema.prototype;\n\n (this.raw.Client as any).Schema.prototype.invalidate = function invalidate(message: string, code: string) {\n if (code === \"implicit-force-https\" || code === \"implicit-forbid-localhost\") {\n return;\n }\n\n /* istanbul ignore next */\n return orig.call(this, message);\n };\n }\n\n private getPolicy() {\n const policy = interactionPolicy.base();\n const interactions = this.oidcInteractions.getInteractions();\n\n if (interactions.length) {\n interactions.forEach((provider) => {\n const {name, ...options} = provider.store.get(\"interactionOptions\");\n\n if (!policy.get(name)) {\n policy.add(\n new interactionPolicy.Prompt({\n name,\n ...options\n })\n );\n }\n\n const instance = this.injector.get(provider.token);\n\n if (instance.$onCreate) {\n instance.$onCreate(policy.get(name));\n }\n });\n }\n\n return this.injector.alter(\"$alterOidcPolicy\", policy);\n }\n}\n"]}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { PlatformContext } from "@tsed/common";
|
|
2
1
|
import { Provider, Account } from "oidc-provider";
|
|
3
2
|
export declare type AuthorizationCode = InstanceType<Provider["AuthorizationCode"]>;
|
|
4
3
|
export declare type AccessToken = InstanceType<Provider["AccessToken"]>;
|
|
5
4
|
export declare type DeviceCode = InstanceType<Provider["DeviceCode"]>;
|
|
6
5
|
export declare type BackchannelAuthenticationRequest = InstanceType<Provider["BackchannelAuthenticationRequest"]>;
|
|
7
6
|
export interface OidcAccountsMethods {
|
|
8
|
-
findAccount(id: string, token: AuthorizationCode | AccessToken | DeviceCode | BackchannelAuthenticationRequest | undefined
|
|
7
|
+
findAccount(id: string, token: AuthorizationCode | AccessToken | DeviceCode | BackchannelAuthenticationRequest | undefined): Promise<Account | undefined>;
|
|
9
8
|
}
|
|
@@ -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;
|
|
@@ -3,12 +3,16 @@ import { JwksKeyParameters } from "@tsed/jwks";
|
|
|
3
3
|
import { Configuration } from "oidc-provider";
|
|
4
4
|
import { OidcAccountsMethods } from "./OidcAccountsMethods";
|
|
5
5
|
export interface OidcSettings extends Configuration {
|
|
6
|
+
/**
|
|
7
|
+
* force the secure cookie. By default, in dev mode it's disabled and in production it's enabled.
|
|
8
|
+
*/
|
|
9
|
+
secureCookies?: boolean;
|
|
6
10
|
/**
|
|
7
11
|
* Path on which the oidc-provider instance is mounted.
|
|
8
12
|
*/
|
|
9
13
|
path?: string;
|
|
10
14
|
/**
|
|
11
|
-
* Issuer URI. By default Ts.ED create issuer with http://localhost:${httpPort}
|
|
15
|
+
* Issuer URI. By default, Ts.ED create issuer with http://localhost:${httpPort}
|
|
12
16
|
*/
|
|
13
17
|
issuer?: string;
|
|
14
18
|
/**
|
|
@@ -27,6 +31,10 @@ export interface OidcSettings extends Configuration {
|
|
|
27
31
|
* Enable proxy.
|
|
28
32
|
*/
|
|
29
33
|
proxy?: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Allow redirect_uri on HTTP protocol and localhost domain.
|
|
36
|
+
*/
|
|
37
|
+
allowHttpLocalhost?: boolean;
|
|
30
38
|
/**
|
|
31
39
|
* Injectable service to manage accounts.
|
|
32
40
|
*/
|
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";
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { OidcInteractions } from "../services/OidcInteractions";
|
|
1
|
+
import { OidcInteractionContext } from "../services/OidcInteractionContext";
|
|
3
2
|
export declare class OidcInteractionMiddleware {
|
|
4
|
-
protected
|
|
5
|
-
|
|
6
|
-
use(context: Context): Promise<void>;
|
|
3
|
+
protected oidcInteractionContext: OidcInteractionContext;
|
|
4
|
+
use(): Promise<void>;
|
|
7
5
|
}
|
|
@@ -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 {
|
|
@@ -11,7 +12,7 @@ export declare class OidcInteractionContext {
|
|
|
11
12
|
protected oidcProvider: OidcProvider;
|
|
12
13
|
protected oidcInteractions: OidcInteractions;
|
|
13
14
|
protected $ctx: PlatformContext;
|
|
14
|
-
|
|
15
|
+
get raw(): OidcInteraction;
|
|
15
16
|
get session(): OidcSession | undefined;
|
|
16
17
|
get prompt(): PromptDetail;
|
|
17
18
|
get params(): Record<string, any>;
|
|
@@ -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
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
+
import { PlatformApplication } from "@tsed/common";
|
|
1
2
|
import { Env } from "@tsed/core";
|
|
2
3
|
import { InjectorService } from "@tsed/di";
|
|
3
|
-
import { Provider as OIDCProvider
|
|
4
|
+
import { Configuration, Provider as OIDCProvider } from "oidc-provider";
|
|
5
|
+
import { OidcSettings } from "../domain/OidcSettings";
|
|
4
6
|
import { OidcAdapters } from "./OidcAdapters";
|
|
5
7
|
import { OidcInteractions } from "./OidcInteractions";
|
|
6
8
|
import { OidcJwks } from "./OidcJwks";
|
|
7
|
-
import { PlatformApplication } from "@tsed/common";
|
|
8
|
-
import { OidcSettings } from "../domain/OidcSettings";
|
|
9
9
|
export declare class OidcProvider {
|
|
10
10
|
raw: OIDCProvider;
|
|
11
11
|
protected env: Env;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/oidc-provider",
|
|
3
|
-
"version": "7.0.0-beta.
|
|
3
|
+
"version": "7.0.0-beta.17",
|
|
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.
|
|
25
|
+
"@tsed/adapters": "7.0.0-beta.17",
|
|
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.
|
|
35
|
-
"@tsed/core": "7.0.0-beta.
|
|
36
|
-
"@tsed/di": "7.0.0-beta.
|
|
37
|
-
"@tsed/exceptions": "7.0.0-beta.
|
|
34
|
+
"@tsed/common": "7.0.0-beta.17",
|
|
35
|
+
"@tsed/core": "7.0.0-beta.17",
|
|
36
|
+
"@tsed/di": "7.0.0-beta.17",
|
|
37
|
+
"@tsed/exceptions": "7.0.0-beta.17",
|
|
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.
|
|
45
|
+
"@tsed/common": "^7.0.0-beta.17",
|
|
46
46
|
"oidc-provider": ">=7.3.0"
|
|
47
47
|
},
|
|
48
48
|
"peerDependenciesMeta": {
|
package/readme.md
CHANGED
|
@@ -62,6 +62,7 @@ import {MemoryAdapter} from "../adapters/MemoryAdapter";
|
|
|
62
62
|
jwksPath: `./../keys/jwks.json`, // don't forget add this path to .gitignore
|
|
63
63
|
Adapter: MemoryAdapter,
|
|
64
64
|
Accounts: Accounts,
|
|
65
|
+
allowHttpLocalhost: false, // by default. true in dev mode and false in production
|
|
65
66
|
// Clients: Clients,
|
|
66
67
|
clients: [
|
|
67
68
|
{
|
|
@@ -106,7 +107,7 @@ Support this project by becoming a sponsor. Your logo will show up here with a l
|
|
|
106
107
|
|
|
107
108
|
The MIT License (MIT)
|
|
108
109
|
|
|
109
|
-
Copyright (c) 2016 -
|
|
110
|
+
Copyright (c) 2016 - 2022 Romain Lenzotti
|
|
110
111
|
|
|
111
112
|
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
113
|
|