@tsed/cli-plugin-oidc-provider 6.0.0-beta.2 → 6.0.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/tsconfig.esm.tsbuildinfo +1 -1
- package/package.json +4 -4
- package/templates/init/src/controllers/oidc/InteractionsController.spec.ts +3 -3
- package/templates/init/src/controllers/oidc/InteractionsController.ts +1 -1
- package/templates/init/src/interactions/AbortInteraction.ts +1 -1
- package/templates/init/src/interactions/ConsentInteraction.spec.ts +7 -7
- package/templates/init/src/interactions/ConsentInteraction.ts +3 -3
- package/templates/init/src/interactions/CustomInteraction.ts +7 -9
- package/templates/init/src/interactions/LoginInteraction.spec.ts +16 -16
- package/templates/init/src/interactions/LoginInteraction.ts +5 -10
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/cli-plugin-oidc-provider",
|
|
3
3
|
"description": "Ts.ED CLI plugin. Add OIDC Provider",
|
|
4
|
-
"version": "6.0.0-beta.
|
|
4
|
+
"version": "6.0.0-beta.3",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/esm/index.js",
|
|
7
7
|
"source": "./src/index.ts",
|
|
@@ -28,9 +28,9 @@
|
|
|
28
28
|
"tslib": "2.7.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@tsed/cli": "6.0.0-beta.
|
|
32
|
-
"@tsed/cli-core": "6.0.0-beta.
|
|
33
|
-
"@tsed/typescript": "6.0.0-beta.
|
|
31
|
+
"@tsed/cli": "6.0.0-beta.3",
|
|
32
|
+
"@tsed/cli-core": "6.0.0-beta.3",
|
|
33
|
+
"@tsed/typescript": "6.0.0-beta.3",
|
|
34
34
|
"cross-env": "7.0.3",
|
|
35
35
|
"typescript": "5.6.2",
|
|
36
36
|
"vitest": "2.1.1"
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {PlatformTest} from "@tsed/platform-http";
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import {getOidcContextFixture} from "../../interactions/__mock__/oidcContext.fixture.js";
|
|
4
|
+
import {InteractionsController} from "./InteractionsController.js";
|
|
5
5
|
|
|
6
6
|
describe("InteractionsController", () => {
|
|
7
7
|
beforeEach(() => PlatformTest.create());
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {PlatformTest} from "@tsed/platform-http";
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import {getOidcContextFixture} from "./__mock__/oidcContext.fixture.js";
|
|
4
|
+
import {ConsentInteraction} from "./ConsentInteraction.js";
|
|
5
5
|
|
|
6
6
|
async function createInteractionFixture() {
|
|
7
7
|
const interaction = await PlatformTest.invoke<ConsentInteraction>(ConsentInteraction, []);
|
|
8
8
|
|
|
9
|
-
return {
|
|
9
|
+
return {interaction};
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
describe("ConsentInteraction", () => {
|
|
@@ -15,7 +15,7 @@ describe("ConsentInteraction", () => {
|
|
|
15
15
|
|
|
16
16
|
describe("$prompt()", () => {
|
|
17
17
|
it("should return consent context", async () => {
|
|
18
|
-
const {
|
|
18
|
+
const {interaction} = await createInteractionFixture();
|
|
19
19
|
const oidcContext = getOidcContextFixture();
|
|
20
20
|
|
|
21
21
|
const result = await interaction.$prompt(oidcContext);
|
|
@@ -36,7 +36,7 @@ describe("ConsentInteraction", () => {
|
|
|
36
36
|
});
|
|
37
37
|
describe("confirm()", () => {
|
|
38
38
|
it("should control all consentement", async () => {
|
|
39
|
-
const {
|
|
39
|
+
const {interaction} = await createInteractionFixture();
|
|
40
40
|
const oidcContext = getOidcContextFixture();
|
|
41
41
|
oidcContext.prompt.name = "consent";
|
|
42
42
|
|
|
@@ -65,7 +65,7 @@ describe("ConsentInteraction", () => {
|
|
|
65
65
|
expect(grant.addOIDCClaims).toHaveBeenCalledWith(["claims"]);
|
|
66
66
|
expect(grant.addResourceScope).toHaveBeenCalledWith("indicator", "scopes");
|
|
67
67
|
expect(grant.save).toHaveBeenCalledWith();
|
|
68
|
-
expect(oidcContext.interactionFinished).toHaveBeenCalledWith({
|
|
68
|
+
expect(oidcContext.interactionFinished).toHaveBeenCalledWith({consent: {grantId: "grantId"}}, {mergeWithLastSubmission: true});
|
|
69
69
|
});
|
|
70
70
|
});
|
|
71
71
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {Post, View, Name} from "@tsed/schema";
|
|
2
|
+
import {Inject} from "@tsed/di";
|
|
2
3
|
import {Interaction, OidcCtx, OidcProvider} from "@tsed/oidc-provider";
|
|
3
|
-
import {Name} from "@tsed/schema";
|
|
4
4
|
|
|
5
5
|
@Interaction({
|
|
6
6
|
name: "consent",
|
|
@@ -32,7 +32,7 @@ export class ConsentInteraction {
|
|
|
32
32
|
missingOIDClaims: string[];
|
|
33
33
|
};
|
|
34
34
|
|
|
35
|
-
const {
|
|
35
|
+
const {missingOIDCScope, missingOIDClaims, missingResourceScopes} = details;
|
|
36
36
|
|
|
37
37
|
if (missingOIDCScope) {
|
|
38
38
|
grant.addOIDCScope(missingOIDCScope.join(" "));
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import {View} from "@tsed/common";
|
|
2
1
|
import {Env} from "@tsed/core";
|
|
3
2
|
import {Constant} from "@tsed/di";
|
|
4
3
|
import {Interaction, InteractionMethods, OidcCtx, OidcSession, Params, Prompt, Uid} from "@tsed/oidc-provider";
|
|
5
|
-
import {Name} from "@tsed/schema";
|
|
4
|
+
import {Name, View} from "@tsed/schema";
|
|
6
5
|
import {interactionPolicy, KoaContextWithOIDC} from "oidc-provider";
|
|
7
6
|
import Check = interactionPolicy.Check;
|
|
8
7
|
|
|
@@ -15,8 +14,7 @@ export class CustomInteraction implements InteractionMethods {
|
|
|
15
14
|
@Constant("env")
|
|
16
15
|
env: Env;
|
|
17
16
|
|
|
18
|
-
$onCreate() {
|
|
19
|
-
}
|
|
17
|
+
$onCreate() {}
|
|
20
18
|
|
|
21
19
|
/**
|
|
22
20
|
* return checks conditions. See: https://github.com/panva/node-oidc-provider/blob/main/docs/README.md#interactionspolicy
|
|
@@ -24,7 +22,7 @@ export class CustomInteraction implements InteractionMethods {
|
|
|
24
22
|
checks() {
|
|
25
23
|
return [
|
|
26
24
|
new Check("no_session", "End-User authentication is required", (ctx) => {
|
|
27
|
-
const {
|
|
25
|
+
const {oidc} = ctx;
|
|
28
26
|
|
|
29
27
|
if (oidc.session?.accountId) {
|
|
30
28
|
// @ts-ignore
|
|
@@ -41,12 +39,12 @@ export class CustomInteraction implements InteractionMethods {
|
|
|
41
39
|
* return checks conditions. See: https://github.com/panva/node-oidc-provider/blob/main/docs/README.md#interactionspolicy
|
|
42
40
|
*/
|
|
43
41
|
details(ctx: KoaContextWithOIDC) {
|
|
44
|
-
const {
|
|
42
|
+
const {oidc} = ctx;
|
|
45
43
|
|
|
46
44
|
return {
|
|
47
|
-
...(oidc.params?.max_age === undefined ? undefined : {
|
|
48
|
-
...(oidc.params?.login_hint === undefined ? undefined : {
|
|
49
|
-
...(oidc.params?.id_token_hint === undefined ? undefined : {
|
|
45
|
+
...(oidc.params?.max_age === undefined ? undefined : {max_age: oidc.params.max_age}),
|
|
46
|
+
...(oidc.params?.login_hint === undefined ? undefined : {login_hint: oidc.params.login_hint}),
|
|
47
|
+
...(oidc.params?.id_token_hint === undefined ? undefined : {id_token_hint: oidc.params.id_token_hint})
|
|
50
48
|
};
|
|
51
49
|
}
|
|
52
50
|
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import {PlatformTest} from "@tsed/platform-http";
|
|
2
|
+
import {catchAsyncError} from "@tsed/core";
|
|
3
|
+
import {BadRequest} from "@tsed/exceptions";
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
5
|
+
import {Accounts} from "../services/Accounts.js";
|
|
6
|
+
import {getOidcContextFixture} from "./__mock__/oidcContext.fixture.js";
|
|
7
|
+
import {LoginInteraction} from "./LoginInteraction.js";
|
|
8
8
|
|
|
9
9
|
async function createInteractionFixture() {
|
|
10
10
|
const accounts = {
|
|
@@ -18,7 +18,7 @@ async function createInteractionFixture() {
|
|
|
18
18
|
}
|
|
19
19
|
]);
|
|
20
20
|
|
|
21
|
-
return {
|
|
21
|
+
return {interaction, accounts};
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
describe("LoginInteraction", () => {
|
|
@@ -30,7 +30,7 @@ describe("LoginInteraction", () => {
|
|
|
30
30
|
|
|
31
31
|
describe("$prompt()", () => {
|
|
32
32
|
it("should return the prompt login context", async () => {
|
|
33
|
-
const {
|
|
33
|
+
const {interaction} = await createInteractionFixture();
|
|
34
34
|
const oidcContext = getOidcContextFixture();
|
|
35
35
|
|
|
36
36
|
const result = await interaction.$prompt(oidcContext);
|
|
@@ -51,7 +51,7 @@ describe("LoginInteraction", () => {
|
|
|
51
51
|
});
|
|
52
52
|
});
|
|
53
53
|
it("should throw error when the Client is unauthorized", async () => {
|
|
54
|
-
const {
|
|
54
|
+
const {interaction} = await createInteractionFixture();
|
|
55
55
|
const oidcContext = getOidcContextFixture();
|
|
56
56
|
|
|
57
57
|
(oidcContext.checkClientId as vi.Mock).mockRejectedValue(new Error("Unknown given client_id: client_id"));
|
|
@@ -64,10 +64,10 @@ describe("LoginInteraction", () => {
|
|
|
64
64
|
});
|
|
65
65
|
describe("submit()", () => {
|
|
66
66
|
it("should find account", async () => {
|
|
67
|
-
const {
|
|
67
|
+
const {interaction, accounts} = await createInteractionFixture();
|
|
68
68
|
const oidcContext = getOidcContextFixture();
|
|
69
69
|
|
|
70
|
-
const payload = {
|
|
70
|
+
const payload = {email: "email@email.com", password: "pwd"};
|
|
71
71
|
|
|
72
72
|
accounts.authenticate.mockResolvedValue({
|
|
73
73
|
accountId: "id"
|
|
@@ -77,13 +77,13 @@ describe("LoginInteraction", () => {
|
|
|
77
77
|
|
|
78
78
|
expect(result).toEqual(undefined);
|
|
79
79
|
expect(oidcContext.checkInteractionName).toHaveBeenCalledWith("login");
|
|
80
|
-
expect(oidcContext.interactionFinished).toHaveBeenCalledWith({
|
|
80
|
+
expect(oidcContext.interactionFinished).toHaveBeenCalledWith({login: {accountId: "id"}});
|
|
81
81
|
});
|
|
82
82
|
it("should return to the login page and return the right context page", async () => {
|
|
83
|
-
const {
|
|
83
|
+
const {interaction, accounts} = await createInteractionFixture();
|
|
84
84
|
const oidcContext = getOidcContextFixture();
|
|
85
85
|
|
|
86
|
-
const payload = {
|
|
86
|
+
const payload = {email: "email@email.com", password: "pwd"};
|
|
87
87
|
|
|
88
88
|
accounts.authenticate.mockResolvedValue(null);
|
|
89
89
|
|
|
@@ -106,7 +106,7 @@ describe("LoginInteraction", () => {
|
|
|
106
106
|
expect(oidcContext.interactionFinished).not.toHaveBeenCalled();
|
|
107
107
|
});
|
|
108
108
|
it("should fail if the prompt name is incorrect", async () => {
|
|
109
|
-
const {
|
|
109
|
+
const {interaction} = await createInteractionFixture();
|
|
110
110
|
const oidcContext = getOidcContextFixture();
|
|
111
111
|
oidcContext.prompt.name = "unknown";
|
|
112
112
|
|
|
@@ -114,7 +114,7 @@ describe("LoginInteraction", () => {
|
|
|
114
114
|
throw new BadRequest("Bad interaction name");
|
|
115
115
|
});
|
|
116
116
|
|
|
117
|
-
const payload = {
|
|
117
|
+
const payload = {email: "email@email.com", password: "pwd"};
|
|
118
118
|
|
|
119
119
|
const error = await catchAsyncError<any>(() => interaction.submit(payload, oidcContext));
|
|
120
120
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {BodyParams
|
|
1
|
+
import {BodyParams} from "@tsed/platform-params";
|
|
2
2
|
import {Env} from "@tsed/core";
|
|
3
|
-
import {Constant} from "@tsed/di";
|
|
3
|
+
import {Constant, Inject} from "@tsed/di";
|
|
4
4
|
import {Interaction, OidcCtx} from "@tsed/oidc-provider";
|
|
5
|
-
import {Name} from "@tsed/schema";
|
|
5
|
+
import {Name, Post, View} from "@tsed/schema";
|
|
6
6
|
import {Accounts} from "../services/Accounts.js";
|
|
7
7
|
|
|
8
8
|
@Interaction({
|
|
@@ -20,9 +20,7 @@ export class LoginInteraction {
|
|
|
20
20
|
$onCreate() {}
|
|
21
21
|
|
|
22
22
|
@View("login")
|
|
23
|
-
async $prompt(
|
|
24
|
-
@OidcCtx() oidcCtx: OidcCtx
|
|
25
|
-
): Promise<any> {
|
|
23
|
+
async $prompt(@OidcCtx() oidcCtx: OidcCtx): Promise<any> {
|
|
26
24
|
await oidcCtx.checkClientId();
|
|
27
25
|
|
|
28
26
|
return oidcCtx.interactionPrompt({
|
|
@@ -33,10 +31,7 @@ export class LoginInteraction {
|
|
|
33
31
|
|
|
34
32
|
@Post("/login")
|
|
35
33
|
@View("login")
|
|
36
|
-
async submit(
|
|
37
|
-
@BodyParams() payload: any,
|
|
38
|
-
@OidcCtx() oidcCtx: OidcCtx
|
|
39
|
-
) {
|
|
34
|
+
async submit(@BodyParams() payload: any, @OidcCtx() oidcCtx: OidcCtx) {
|
|
40
35
|
oidcCtx.checkInteractionName("login");
|
|
41
36
|
|
|
42
37
|
const account = await this.accounts.authenticate(payload.email, payload.password);
|