From 1de71a4feb0e64aa4d77435ad299b15809b682a5 Mon Sep 17 00:00:00 2001 From: Samuele Salvatico Date: Mon, 8 Jul 2024 15:55:53 +0200 Subject: [PATCH 1/5] chore(core): node to 20.10.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 28ff7ea7f52..68e563f8f8a 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ "typescript": "^5.0.0" }, "engines": { - "node": "^20.9.0", + "node": "^20.10.0", "pnpm": "^9.0.0" }, "pnpm": { From da1937c6f1ad73de3a8edd1223236e95920f5eab Mon Sep 17 00:00:00 2001 From: Samuele Salvatico Date: Tue, 9 Jul 2024 12:02:47 +0200 Subject: [PATCH 2/5] chore(connector): fixed oid for users --- .../src/routes/logto/index.ts | 30 ++++++++++++------- .../src/routes/logto/utils/index.ts | 6 ++-- .../src/routes/static/mock-login.html | 18 +++++++++-- 3 files changed, 39 insertions(+), 15 deletions(-) diff --git a/mygovid-mock-service/src/routes/logto/index.ts b/mygovid-mock-service/src/routes/logto/index.ts index 9f62eb86377..63fc55b2e9e 100644 --- a/mygovid-mock-service/src/routes/logto/index.ts +++ b/mygovid-mock-service/src/routes/logto/index.ts @@ -43,14 +43,14 @@ export default async function login(app: FastifyInstance) { const { redirect_uri, state } = request.query; const stream = fs.createReadStream( - path.join(__dirname, "..", "static", "mock-login.html") + path.join(__dirname, "..", "static", "mock-login.html"), ); const result = (await streamToString(stream)) .replace("%REDIRECT_URL%", redirect_uri) .replace("%STATE%", state); return reply.type("text/html").send(result); - } + }, ); app.post<{ @@ -61,19 +61,29 @@ export default async function login(app: FastifyInstance) { email: string; redirect_url: string; state: string; + sub: string; + oid: string; }; }>("/login", async (request, reply) => { - const { password, firstName, lastName, email, redirect_url, state } = - request.body; + const { + password, + firstName, + lastName, + email, + redirect_url, + state, + sub, + oid, + } = request.body; if (password !== "123") reply.redirect( - `/logto/mock/auth?redirect_uri=${redirect_url}&state=${state}` + `/logto/mock/auth?redirect_uri=${redirect_url}&state=${state}`, ); const id_token = await createMockSignedJwt( - { firstName, lastName, email }, - request.headers.origin as unknown as string + { firstName, lastName, email, sub, oid }, + request.headers.origin as unknown as string, ); return reply.redirect(`${redirect_url}?code=${id_token}&state=${state}`); @@ -140,7 +150,7 @@ export default async function login(app: FastifyInstance) { "eyJ2ZXIiOiIxLjAiLCJ0aWQiOiI4OTc5MmE2ZC0xZWE0LTQxMjYtOTRkZi1hNzFkMjkyZGViYzciLCJzdWIiOm51bGwsIm5hbWUiOm51bGwsInByZWZlcnJlZF91c2VybmFtZSI6bnVsbCwiaWRwIjpudWxsfQ", scope: "openid", }; - } + }, ); app.get<{ @@ -167,7 +177,7 @@ export default async function login(app: FastifyInstance) { kty: Type.Optional(Type.String()), n: Type.Optional(Type.String()), e: Type.Optional(Type.String()), - }) + }), ), }), 500: HttpError, @@ -181,6 +191,6 @@ export default async function login(app: FastifyInstance) { return { keys: [{ kid: "signingkey.mygovid.v1", use: "sig", kty, n, e }], }; - } + }, ); } diff --git a/mygovid-mock-service/src/routes/logto/utils/index.ts b/mygovid-mock-service/src/routes/logto/utils/index.ts index 689abff07cf..2c219595812 100644 --- a/mygovid-mock-service/src/routes/logto/utils/index.ts +++ b/mygovid-mock-service/src/routes/logto/utils/index.ts @@ -33,15 +33,17 @@ export const createMockSignedJwt = async ( firstName: string; lastName: string; email: string; + sub: string; + oid: string; }, origin: string, ) => { const body = { ver: "1.0", - sub: getRandomString(), + sub: user.sub, auth_time: Date.now(), email: user.email, - oid: getRandomString(), + oid: user.oid, AlternateIds: "", BirthDate: "13/06/1941", PublicServiceNumber: "0111019P", diff --git a/mygovid-mock-service/src/routes/static/mock-login.html b/mygovid-mock-service/src/routes/static/mock-login.html index f811e401f86..a7fd40916f6 100644 --- a/mygovid-mock-service/src/routes/static/mock-login.html +++ b/mygovid-mock-service/src/routes/static/mock-login.html @@ -84,6 +84,8 @@ /> + + user.govid_email === e.target.value, ); - let firstName, lastName, email; + let firstName, lastName, email, oid, sub; if (user) { const nameSplit = user.user_name.split(" "); @@ -242,16 +248,22 @@ lastName = nameSplit.slice(1).join(" "); email = user.govid_email; isCurrentUserSet = true; + oid = user.oid; + sub = user.sub; } else { firstName = faker.person.firstName(); lastName = faker.person.lastName(); email = `${firstName.toLowerCase()}.${lastName.toLowerCase()}@mail.ie`; isCurrentUserSet = false; + oid = crypto.randomBytes(20).toString("hex"); + sub = crypto.randomBytes(20).toString("hex"); } document.querySelector("#firstName").value = firstName; document.querySelector("#lastName").value = lastName; document.querySelector("#email").value = email; + document.querySelector("#oid").value = oid; + document.querySelector("#sub").value = sub; document.querySelector("#submit_btn").innerHTML = `
Login ${firstName} ${lastName}
`; }); From 39184a249b2a1d6ded7c17a37145505fecd89995 Mon Sep 17 00:00:00 2001 From: Samuele Salvatico Date: Tue, 9 Jul 2024 14:44:46 +0200 Subject: [PATCH 3/5] chore(core): added .env.sample --- .env.sample | 4 ++++ makefile | 3 +++ 2 files changed, 7 insertions(+) create mode 100644 .env.sample diff --git a/.env.sample b/.env.sample new file mode 100644 index 00000000000..4be507967a9 --- /dev/null +++ b/.env.sample @@ -0,0 +1,4 @@ +DB_URL=postgresql://postgres:p0stgr3s@localhost:5433/postgres +PORT=3301 +ADMIN_PORT=3302 +TRUST_PROXY_HEADER=1 \ No newline at end of file diff --git a/makefile b/makefile index 49ddf394a5f..39a17af40ea 100644 --- a/makefile +++ b/makefile @@ -10,6 +10,9 @@ run: down: docker-compose -f docker-compose-local.yml down run-native: + @echo "${GREEN}Copying .env file...${NC}" + cp -- ".env.sample" ".env" + @echo "${GREEN}Copied!${NC}" @echo "${GREEN}Starting db...${NC}" docker compose -f docker-compose-local.yml up --detach postgres @echo "${GREEN}Db started!${NC}" From f2425777f0edba926de1c559d041e256886d647f Mon Sep 17 00:00:00 2001 From: Samuele Salvatico Date: Tue, 9 Jul 2024 15:35:19 +0200 Subject: [PATCH 4/5] chore(core): add ogcio env vars --- .env.sample | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/.env.sample b/.env.sample index 4be507967a9..e35554989cb 100644 --- a/.env.sample +++ b/.env.sample @@ -1,4 +1,9 @@ -DB_URL=postgresql://postgres:p0stgr3s@localhost:5433/postgres -PORT=3301 +# Default config +TRUST_PROXY_HEADER=1 +DB_URL=postgresql://postgres:p0stgr3s@localhost:5433/logto ADMIN_PORT=3302 -TRUST_PROXY_HEADER=1 \ No newline at end of file +PORT=3301 + +# OGCIO Config +MOCK_TOKEN_ENDPOINT=http://localhost:4005/logto/mock/token +MOCK_KEYS_ENDPOINT=http://localhost:4005/logto/mock/keys \ No newline at end of file From c2ee18f294f9c2c5087e1b658f8fd5e433b28fc6 Mon Sep 17 00:00:00 2001 From: Samuele Salvatico Date: Tue, 9 Jul 2024 16:08:34 +0200 Subject: [PATCH 5/5] chore(core): updated webhooks --- .../cli/src/commands/database/ogcio/ogcio-seeder-dev.json | 8 +++++--- .../src/commands/database/ogcio/ogcio-seeder-local.json | 8 +++++--- .../cli/src/commands/database/ogcio/ogcio-seeder.json | 8 +++++--- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/packages/cli/src/commands/database/ogcio/ogcio-seeder-dev.json b/packages/cli/src/commands/database/ogcio/ogcio-seeder-dev.json index a56a5d3c7f3..cc829d349b7 100644 --- a/packages/cli/src/commands/database/ogcio/ogcio-seeder-dev.json +++ b/packages/cli/src/commands/database/ogcio/ogcio-seeder-dev.json @@ -100,8 +100,10 @@ "id": "login_webhook", "name": "User log in", "events": [ - "PostRegister", - "PostSignIn" + "User.Created", + "User.Deleted", + "User.Data.Updated", + "User.SuspensionStatus.Updated" ], "config": { "url": "" @@ -111,4 +113,4 @@ } ] } -} +} \ No newline at end of file diff --git a/packages/cli/src/commands/database/ogcio/ogcio-seeder-local.json b/packages/cli/src/commands/database/ogcio/ogcio-seeder-local.json index edf180ff1aa..f3c2a608ac3 100644 --- a/packages/cli/src/commands/database/ogcio/ogcio-seeder-local.json +++ b/packages/cli/src/commands/database/ogcio/ogcio-seeder-local.json @@ -179,8 +179,10 @@ "id": "login-webhook", "name": "User log in", "events": [ - "PostRegister", - "PostSignIn" + "User.Created", + "User.Deleted", + "User.Data.Updated", + "User.SuspensionStatus.Updated" ], "config": { "url": "http://localhost:8003/user-login-wh" @@ -190,4 +192,4 @@ } ] } -} +} \ No newline at end of file diff --git a/packages/cli/src/commands/database/ogcio/ogcio-seeder.json b/packages/cli/src/commands/database/ogcio/ogcio-seeder.json index 33fb4ced0c7..319808bd006 100644 --- a/packages/cli/src/commands/database/ogcio/ogcio-seeder.json +++ b/packages/cli/src/commands/database/ogcio/ogcio-seeder.json @@ -179,8 +179,10 @@ "id": "login-webhook", "name": "User log in", "events": [ - "PostRegister", - "PostSignIn" + "User.Created", + "User.Deleted", + "User.Data.Updated", + "User.SuspensionStatus.Updated" ], "config": { "url": "" @@ -190,4 +192,4 @@ } ] } -} +} \ No newline at end of file