Skip to content

Commit e309615

Browse files
committed
feat: go back button, goes back to PCF instead of going to change-email page
1 parent 406f060 commit e309615

File tree

17 files changed

+96
-77
lines changed

17 files changed

+96
-77
lines changed

assets/js/go-back.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
document.addEventListener(
22
"DOMContentLoaded",
33
function () {
4-
var goBackLink = document.getElementById("go-back-link");
4+
var goBackLinks = document.querySelectorAll(".go-back-link");
55

66
function goBack() {
77
history.back();
88
}
99

10-
goBackLink.addEventListener("click", goBack);
10+
goBackLinks.forEach(function (goBackLink) {
11+
goBackLink.addEventListener("click", goBack);
12+
});
1113
},
1214
false,
1315
);

cypress/e2e/signin_from_proconnect_federation_client/fixtures.sql

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ INSERT INTO oidc_clients
2121
(client_name, client_id, client_secret, redirect_uris,
2222
post_logout_redirect_uris, scope, client_uri, client_description,
2323
userinfo_signed_response_alg, id_token_signed_response_alg,
24-
authorization_signed_response_alg, introspection_signed_response_alg)
24+
authorization_signed_response_alg, introspection_signed_response_alg,
25+
is_proconnect_federation)
2526
VALUES
2627
(
2728
'ProConnect Federation',
@@ -34,4 +35,5 @@ VALUES
3435
'openid uid given_name usual_name email phone siret is_service_public is_public_service',
3536
'http://localhost:4001/',
3637
'Dispositif d’identification des agents de la fonction publique.',
37-
'ES256', 'ES256', 'ES256', 'ES256');
38+
'ES256', 'ES256', 'ES256', 'ES256',
39+
true);

cypress/e2e/signin_from_proconnect_federation_client/index.cy.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,13 @@ describe("sign-in from proconnect federation client", () => {
4141
cy.contains("moncomptepro-proconnect-federation-client");
4242
cy.contains("unused1@yopmail.com");
4343
});
44+
45+
it("should go back to the Federation client when hitting the change email button", () => {
46+
cy.visit("http://localhost:4001");
47+
cy.get("button.proconnect-button").click();
48+
49+
cy.get("#change-email-address").click();
50+
51+
cy.contains("moncomptepro-proconnect-federation-client");
52+
});
4453
});
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
exports.shorthands = undefined;
2+
3+
exports.up = async (pgm) => {
4+
await pgm.db.query(`
5+
ALTER TABLE oidc_clients
6+
ADD COLUMN is_proconnect_federation boolean NOT NULL DEFAULT FALSE;
7+
`);
8+
};
9+
10+
exports.down = async (pgm) => {
11+
await pgm.db.query(`
12+
ALTER TABLE oidc_clients
13+
DROP COLUMN is_proconnect_federation;
14+
`);
15+
};

scripts/create-anonymized-copy-of-database.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ SELECT
8484
userinfo_signed_response_alg,
8585
id_token_signed_response_alg,
8686
authorization_signed_response_alg,
87-
introspection_signed_response_alg
87+
introspection_signed_response_alg,
88+
is_proconnect_federation
8889
FROM oidc_clients"
8990
psql $SRC_DB_URL --command="ALTER TABLE tmp_oidc_clients ADD PRIMARY KEY (id)"
9091
pg_dump --table=tmp_oidc_clients $SRC_DB_URL | psql $DEST_DB_URL

scripts/fixtures.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,3 +1088,7 @@ SELECT setval(
10881088
(SELECT last_value FROM oidc_clients_id_seq)
10891089
)
10901090
);
1091+
1092+
UPDATE oidc_clients
1093+
SET is_proconnect_federation = true
1094+
WHERE id = 15;

src/controllers/interaction.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
isWithinTwoFactorAuthenticatedSession,
99
} from "../managers/session/authenticated";
1010
import { setLoginHintInUnauthenticatedSession } from "../managers/session/unauthenticated";
11+
import { findByClientId } from "../repositories/oidc-client";
1112
import epochTime from "../services/epoch-time";
1213
import { mustReturnOneOrganizationInPayload } from "../services/must-return-one-organization-in-payload";
1314
import { shouldTrigger2fa } from "../services/should-trigger-2fa";
@@ -18,7 +19,7 @@ export const interactionStartControllerFactory =
1819
try {
1920
const {
2021
uid: interactionId,
21-
params: { login_hint, scope },
22+
params: { client_id, login_hint, scope },
2223
prompt,
2324
} = await oidcProvider.interactionDetails(req, res);
2425

@@ -29,6 +30,10 @@ export const interactionStartControllerFactory =
2930
req.session.mustUse2FA = true;
3031
}
3132

33+
const oidcClient = await findByClientId(client_id);
34+
req.session.authForProconnectFederation =
35+
oidcClient?.is_proconnect_federation;
36+
3237
if (login_hint) {
3338
setLoginHintInUnauthenticatedSession(req, login_hint);
3439
}
@@ -102,6 +107,7 @@ export const interactionEndControllerFactory =
102107
req.session.interactionId = undefined;
103108
req.session.mustReturnOneOrganizationInPayload = undefined;
104109
req.session.mustUse2FA = undefined;
110+
req.session.authForProconnectFederation = undefined;
105111

106112
await oidcProvider.interactionFinished(req, res, result);
107113
} catch (error) {

src/controllers/user/signin-signup.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ export const getSignInController = async (
170170
csrfToken: csrfToken(req),
171171
email,
172172
showPasskeySection: hasWebauthnConfigured,
173+
changeEmailButtonMustReturnToPCF: req.session.authForProconnectFederation,
173174
});
174175
} catch (error) {
175176
next(error);
@@ -218,10 +219,12 @@ export const getSignUpController = async (
218219
const { login_hint } = await schema.parseAsync(req.query);
219220

220221
return res.render("user/sign-up", {
222+
pageTitle: "Choisir votre mot de passe",
221223
notifications: await getNotificationsFromRequest(req),
222224
csrfToken: csrfToken(req),
223225
loginHint: login_hint,
224226
email: getEmailFromUnauthenticatedSession(req),
227+
changeEmailButtonMustReturnToPCF: req.session.authForProconnectFederation,
225228
});
226229
} catch (error) {
227230
next(error);

src/managers/session/authenticated.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export const createAuthenticatedSession = async (
5353
mustReturnOneOrganizationInPayload,
5454
mustUse2FA,
5555
referrerPath,
56+
authForProconnectFederation,
5657
} = req.session;
5758

5859
// as selected org is not stored in session,
@@ -77,6 +78,7 @@ export const createAuthenticatedSession = async (
7778
mustReturnOneOrganizationInPayload;
7879
req.session.mustUse2FA = mustUse2FA;
7980
req.session.referrerPath = referrerPath;
81+
req.session.authForProconnectFederation = authForProconnectFederation;
8082
// new session reset amr
8183
req.session.amr = [];
8284

src/repositories/oidc-client.ts

Lines changed: 3 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,7 @@ export const getClients = async () => {
66

77
const { rows }: QueryResult<OidcClient> = await connection.query(`
88
SELECT
9-
id,
10-
client_description,
11-
created_at,
12-
updated_at,
13-
client_name,
14-
client_id,
15-
client_secret,
16-
redirect_uris,
17-
post_logout_redirect_uris,
18-
scope,
19-
client_uri,
20-
userinfo_signed_response_alg,
21-
id_token_signed_response_alg,
22-
authorization_signed_response_alg,
23-
introspection_signed_response_alg
9+
*
2410
FROM oidc_clients
2511
`);
2612

@@ -33,21 +19,7 @@ export const findByClientId = async (client_id: string) => {
3319
const { rows }: QueryResult<OidcClient> = await connection.query(
3420
`
3521
SELECT
36-
id,
37-
client_description,
38-
created_at,
39-
updated_at,
40-
client_name,
41-
client_id,
42-
client_secret,
43-
redirect_uris,
44-
post_logout_redirect_uris,
45-
scope,
46-
client_uri,
47-
userinfo_signed_response_alg,
48-
id_token_signed_response_alg,
49-
authorization_signed_response_alg,
50-
introspection_signed_response_alg
22+
*
5123
FROM oidc_clients
5224
WHERE client_id = $1
5325
`,
@@ -63,21 +35,7 @@ export const getByUserIdOrderedByConnectionCount = async (user_id: number) => {
6335
const { rows }: QueryResult<OidcClient> = await connection.query(
6436
`
6537
SELECT
66-
oc.id,
67-
oc.client_description,
68-
oc.created_at,
69-
oc.updated_at,
70-
oc.client_name,
71-
oc.client_id,
72-
oc.client_secret,
73-
oc.redirect_uris,
74-
oc.post_logout_redirect_uris,
75-
oc.scope,
76-
oc.client_uri,
77-
oc.userinfo_signed_response_alg,
78-
oc.id_token_signed_response_alg,
79-
oc.authorization_signed_response_alg,
80-
oc.introspection_signed_response_alg
38+
oc.*
8139
FROM (
8240
SELECT
8341
user_id,

0 commit comments

Comments
 (0)