@tsed/cli-plugin-oidc-provider 4.0.1 → 4.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +5 -5
- package/templates/init/src/controllers/oidc/InteractionsController.spec.ts +2 -2
- package/templates/init/src/controllers/oidc/InteractionsController.ts +3 -3
- package/templates/init/src/interactions/AbortInteraction.ts +26 -0
- package/templates/init/src/interactions/ConsentInteraction.ts +2 -1
- package/templates/init/src/interactions/CustomInteraction.ts +56 -8
- package/templates/init/src/interactions/LoginInteraction.ts +2 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/cli-plugin-oidc-provider",
|
|
3
|
-
"version": "4.0
|
|
3
|
+
"version": "4.2.0",
|
|
4
4
|
"description": "Ts.ED CLI plugin. Add OIDC Provider",
|
|
5
5
|
"source": "./src/index.ts",
|
|
6
6
|
"main": "./lib/cjs/index.js",
|
|
@@ -25,12 +25,12 @@
|
|
|
25
25
|
"tslib": "2.3.1"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@tsed/cli": "4.0
|
|
29
|
-
"@tsed/cli-core": "4.0
|
|
28
|
+
"@tsed/cli": "4.2.0",
|
|
29
|
+
"@tsed/cli-core": "4.2.0"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
|
-
"@tsed/cli": "^4.0
|
|
33
|
-
"@tsed/cli-core": "^4.0
|
|
32
|
+
"@tsed/cli": "^4.2.0",
|
|
33
|
+
"@tsed/cli-core": "^4.2.0"
|
|
34
34
|
},
|
|
35
35
|
"repository": "https://github.com/tsedio/tsed-cli",
|
|
36
36
|
"bugs": {
|
|
@@ -12,9 +12,9 @@ describe("InteractionsController", () => {
|
|
|
12
12
|
const oidcContext = getOidcContextFixture();
|
|
13
13
|
const controller = await PlatformTest.invoke<InteractionsController>(InteractionsController);
|
|
14
14
|
|
|
15
|
-
await controller.promptInteraction(oidcContext);
|
|
15
|
+
await controller.promptInteraction("name", oidcContext);
|
|
16
16
|
|
|
17
|
-
expect(oidcContext.runInteraction).toHaveBeenCalledWith();
|
|
17
|
+
expect(oidcContext.runInteraction).toHaveBeenCalledWith("name");
|
|
18
18
|
});
|
|
19
19
|
});
|
|
20
20
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {Get} from "@tsed/common";
|
|
1
|
+
import {Get, PathParams} from "@tsed/common";
|
|
2
2
|
import {Interactions, OidcCtx} from "@tsed/oidc-provider";
|
|
3
3
|
import {Name} from "@tsed/schema";
|
|
4
4
|
import * as interactions from "../../interactions/index";
|
|
@@ -9,8 +9,8 @@ import * as interactions from "../../interactions/index";
|
|
|
9
9
|
children: Object.values(interactions)
|
|
10
10
|
})
|
|
11
11
|
export class InteractionsController {
|
|
12
|
-
@Get("
|
|
13
|
-
async promptInteraction(@OidcCtx() oidcCtx: OidcCtx) {
|
|
12
|
+
@Get("/:name?")
|
|
13
|
+
async promptInteraction(@PathParams("name") name: string | undefined, @OidcCtx() oidcCtx: OidcCtx) {
|
|
14
14
|
return oidcCtx.runInteraction();
|
|
15
15
|
}
|
|
16
16
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import {Inject} from "@tsed/common";
|
|
2
|
+
import {Interaction, OidcCtx, OidcProvider, InteractionMethods} from "@tsed/oidc-provider";
|
|
3
|
+
import {View} from "@tsed/platform-views";
|
|
4
|
+
import {Name} from "@tsed/schema";
|
|
5
|
+
|
|
6
|
+
@Interaction({
|
|
7
|
+
name: "abort"
|
|
8
|
+
})
|
|
9
|
+
@Name("Oidc")
|
|
10
|
+
export class AbortInteraction implements InteractionMethods {
|
|
11
|
+
@Inject()
|
|
12
|
+
oidc: OidcProvider;
|
|
13
|
+
|
|
14
|
+
@View("interaction")
|
|
15
|
+
async $prompt(@OidcCtx() oidcCtx: OidcCtx): Promise<any> {
|
|
16
|
+
return oidcCtx.interactionFinished(
|
|
17
|
+
{
|
|
18
|
+
error: "access_denied",
|
|
19
|
+
error_description: "End-User aborted interaction"
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
mergeWithLastSubmission: false
|
|
23
|
+
}
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -1,20 +1,68 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {View} from "@tsed/common";
|
|
2
2
|
import {Env} from "@tsed/core";
|
|
3
3
|
import {Constant} from "@tsed/di";
|
|
4
|
-
import {Interaction} from "@tsed/oidc-provider";
|
|
4
|
+
import {Interaction, InteractionMethods, OidcCtx, OidcSession, Params, Prompt, Uid} from "@tsed/oidc-provider";
|
|
5
5
|
import {Name} from "@tsed/schema";
|
|
6
|
-
import {
|
|
6
|
+
import {interactionPolicy, KoaContextWithOIDC} from "oidc-provider";
|
|
7
|
+
import Check = interactionPolicy.Check;
|
|
7
8
|
|
|
8
9
|
@Interaction({
|
|
9
|
-
name: "custom"
|
|
10
|
+
name: "custom",
|
|
11
|
+
requestable: true
|
|
10
12
|
})
|
|
11
13
|
@Name("Oidc")
|
|
12
|
-
export class CustomInteraction {
|
|
14
|
+
export class CustomInteraction implements InteractionMethods {
|
|
13
15
|
@Constant("env")
|
|
14
16
|
env: Env;
|
|
15
17
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
+
$onCreate() {
|
|
19
|
+
}
|
|
18
20
|
|
|
19
|
-
|
|
21
|
+
/**
|
|
22
|
+
* return checks conditions. See: https://github.com/panva/node-oidc-provider/blob/main/docs/README.md#interactionspolicy
|
|
23
|
+
*/
|
|
24
|
+
checks() {
|
|
25
|
+
return [
|
|
26
|
+
new Check("no_session", "End-User authentication is required", (ctx) => {
|
|
27
|
+
const { oidc } = ctx;
|
|
28
|
+
|
|
29
|
+
if (oidc.session?.accountId) {
|
|
30
|
+
// @ts-ignore
|
|
31
|
+
return Check.NO_NEED_TO_PROMPT;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// @ts-ignore
|
|
35
|
+
return Check.REQUEST_PROMPT;
|
|
36
|
+
})
|
|
37
|
+
];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* return checks conditions. See: https://github.com/panva/node-oidc-provider/blob/main/docs/README.md#interactionspolicy
|
|
42
|
+
*/
|
|
43
|
+
details(ctx: KoaContextWithOIDC) {
|
|
44
|
+
const { oidc } = ctx;
|
|
45
|
+
|
|
46
|
+
return {
|
|
47
|
+
...(oidc.params?.max_age === undefined ? undefined : { max_age: oidc.params.max_age }),
|
|
48
|
+
...(oidc.params?.login_hint === undefined ? undefined : { login_hint: oidc.params.login_hint }),
|
|
49
|
+
...(oidc.params?.id_token_hint === undefined ? undefined : { id_token_hint: oidc.params.id_token_hint })
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
@View("custom")
|
|
54
|
+
async $prompt(
|
|
55
|
+
@OidcCtx() oidcCtx: OidcCtx,
|
|
56
|
+
@Prompt() prompt: Prompt,
|
|
57
|
+
@OidcSession() session: OidcSession,
|
|
58
|
+
@Params() params: Params,
|
|
59
|
+
@Uid() uid: Uid
|
|
60
|
+
): Promise<any> {
|
|
61
|
+
await oidcCtx.checkClientId();
|
|
62
|
+
|
|
63
|
+
return oidcCtx.interactionPrompt({
|
|
64
|
+
title: "Custom",
|
|
65
|
+
flash: false
|
|
66
|
+
});
|
|
67
|
+
}
|
|
20
68
|
}
|