-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(user): add certification routes
- Loading branch information
1 parent
2e9d9b8
commit 1beee87
Showing
26 changed files
with
690 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
DO_NOT_SEND_MAIL="True" |
36 changes: 36 additions & 0 deletions
36
cypress/e2e/signin_with_certification_dirigeant/fixtures.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
INSERT INTO users | ||
(id, email, email_verified, email_verified_at, encrypted_password, created_at, updated_at, | ||
given_name, family_name, phone_number, job, encrypted_totp_key, totp_key_verified_at, force_2fa) | ||
VALUES | ||
(1, '[email protected]', true, CURRENT_TIMESTAMP, | ||
'$2a$10$kzY3LINL6..50Fy9shWCcuNlRfYq0ft5lS.KCcJ5PzrhlWfKK4NIO', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, | ||
'Jean', 'Certification', '0123456789', 'Dirigeant', | ||
null, null, false); | ||
|
||
INSERT INTO organizations | ||
(id, siret, created_at, updated_at) | ||
VALUES | ||
(1, '21340126800130', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP); | ||
|
||
INSERT INTO users_organizations | ||
(user_id, organization_id, is_external, verification_type, has_been_greeted) | ||
VALUES | ||
(1, 1, false, 'domain', true); | ||
|
||
INSERT INTO oidc_clients | ||
(client_name, client_id, client_secret, redirect_uris, | ||
post_logout_redirect_uris, scope, client_uri, client_description, | ||
userinfo_signed_response_alg, id_token_signed_response_alg, | ||
authorization_signed_response_alg, introspection_signed_response_alg) | ||
VALUES | ||
('Oidc Test Client', | ||
'standard_client_id', | ||
'standard_client_secret', | ||
ARRAY [ | ||
'http://localhost:4000/login-callback' | ||
], | ||
ARRAY []::varchar[], | ||
'openid email profile organization', | ||
'http://localhost:4000/', | ||
'ProConnect test client. More info: https://github.com/numerique-gouv/proconnect-test-client.', | ||
null, null, null, null); |
40 changes: 40 additions & 0 deletions
40
cypress/e2e/signin_with_certification_dirigeant/index.cy.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
describe("sign-in with a client requiring certification dirigeant", () => { | ||
beforeEach(() => { | ||
cy.visit("http://localhost:4000"); | ||
cy.setRequestedAcrs([ | ||
"https://proconnect.gouv.fr/assurance/certification-dirigeant", | ||
]); | ||
}); | ||
|
||
it("should sign-in an return the right acr value", function () { | ||
cy.get("button#custom-connection").click({ force: true }); | ||
cy.login("[email protected]"); | ||
|
||
cy.contains("Authentifier votre statut"); | ||
cy.contains("S’identifier avec").click(); | ||
|
||
cy.origin("https://fcp.integ01.dev-franceconnect.fr", () => { | ||
cy.contains("FIP1-LOW - eIDAS LOW").click(); | ||
}); | ||
cy.origin("https://fip1-low.integ01.fcp.fournisseur-d-identite.fr", () => { | ||
cy.contains("Mot de passe").click(); | ||
cy.focused().type("123"); | ||
cy.contains("Valider").click(); | ||
}); | ||
cy.origin("https://fcp.integ01.dev-franceconnect.fr", () => { | ||
cy.contains("Continuer sur FSPublic").click(); | ||
}); | ||
|
||
cy.contains("Vous allez vous connecter en tant que "); | ||
cy.contains("Angela Claire Louise DUBOIS"); | ||
|
||
cy.contains( | ||
"J'accepte que FranceConnect transmette mes données au service pour me connecter", | ||
).click(); | ||
cy.contains("Continuer").click(); | ||
|
||
cy.contains( | ||
'"acr": "https://proconnect.gouv.fr/assurance/certification-dirigeant"', | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -117,6 +117,12 @@ describe("sign-in with a client requiring certification dirigeant identity", () | |
cy.get("button#custom-connection").click({ force: true }); | ||
|
||
cy.login("[email protected]"); | ||
cy.contains("S’identifier avec").click(); | ||
cy.contains( | ||
"J'accepte que FranceConnect transmette mes données au service pour me connecter", | ||
).click(); | ||
cy.contains("Continuer").click(); | ||
cy.contains("Continuer").click(); | ||
|
||
cy.contains( | ||
'"acr": "https://proconnect.gouv.fr/assurance/certification-dirigeant"', | ||
|
@@ -154,7 +160,7 @@ describe("sign-in with a client requiring certification dirigeant and 2fa identi | |
}); | ||
}); | ||
|
||
describe("qign-in with a the requiring certification dirigeant and consistency-checked", () => { | ||
describe("sign-in with a client requiring certification dirigeant and consistency-checked", () => { | ||
beforeEach(() => { | ||
cy.visit("http://localhost:4000"); | ||
cy.setRequestedAcrs([ | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
packages/identite/src/certification/executive/get-franceconnect-user.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
// | ||
|
||
import { | ||
authorizationCodeGrant, | ||
buildAuthorizationUrl, | ||
ClientSecretPost, | ||
Configuration, | ||
fetchUserInfo, | ||
randomNonce, | ||
randomState, | ||
} from "openid-client"; | ||
import { z } from "zod"; | ||
import { | ||
FranceConnectUserInfoSchema, | ||
type FranceConnectUserInfo, | ||
} from "../../types/franceconnect.schema.js"; | ||
|
||
// | ||
|
||
export function getFranceConnectConfigurationFactory( | ||
server: URL, | ||
clientId: string, | ||
clientSecret: string, | ||
) { | ||
return function getFranceConnectConfiguration() { | ||
const serverUri = server.toString(); | ||
return new Configuration( | ||
{ | ||
authorization_endpoint: `${serverUri}/authorize`, | ||
issuer: server.origin, | ||
jwks_uri: `${serverUri}/jwks`, | ||
token_endpoint: `${serverUri}/token`, | ||
userinfo_endpoint: `${serverUri}/userinfo`, | ||
token_endpoint_auth_method: "client_secret_basic", | ||
}, | ||
clientId, | ||
{ | ||
id_token_signed_response_alg: "HS256", | ||
}, | ||
ClientSecretPost(clientSecret), | ||
); | ||
}; | ||
} | ||
export type GetFranceConnectConfigurationHandler = ReturnType< | ||
typeof getFranceConnectConfigurationFactory | ||
>; | ||
|
||
export function createChecks() { | ||
return { | ||
state: randomState(), | ||
nonce: randomNonce(), | ||
}; | ||
} | ||
|
||
export function getFranceConnectRedirectUrlFactory( | ||
getConfiguration: GetFranceConnectConfigurationHandler, | ||
parameters: { | ||
callbackUrl: string; | ||
scope: string; | ||
}, | ||
) { | ||
const { callbackUrl, scope } = parameters; | ||
return async function getFranceConnectUser(nonce: string, state: string) { | ||
const config = getConfiguration(); | ||
return buildAuthorizationUrl( | ||
config, | ||
new URLSearchParams({ | ||
nonce, | ||
redirect_uri: callbackUrl, | ||
scope, | ||
state, | ||
}), | ||
); | ||
}; | ||
} | ||
|
||
export function getFranceConnectUserFactory( | ||
getConfiguration: GetFranceConnectConfigurationHandler, | ||
) { | ||
return async function getFranceConnectUser(parameters: { | ||
code: string; | ||
currentUrl: string; | ||
expectedNonce: string; | ||
expectedState: string; | ||
}) { | ||
const { code, currentUrl, expectedNonce, expectedState } = parameters; | ||
const config = getConfiguration(); | ||
const tokens = await authorizationCodeGrant( | ||
config, | ||
new URL(currentUrl), | ||
{ | ||
expectedNonce, | ||
expectedState, | ||
}, | ||
{ code }, | ||
); | ||
const claims = tokens.claims(); | ||
|
||
const { sub } = await z | ||
.object({ | ||
sub: z.string(), | ||
}) | ||
.parseAsync(claims); | ||
const userInfo = await fetchUserInfo(config, tokens.access_token, sub); | ||
return FranceConnectUserInfoSchema.passthrough().parseAsync( | ||
userInfo, | ||
) as Promise<FranceConnectUserInfo>; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// | ||
|
||
export * from "./get-franceconnect-user.js"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// | ||
|
||
import { z } from "zod"; | ||
|
||
// | ||
|
||
/** | ||
* @see https://docs.partenaires.franceconnect.gouv.fr/fs/fs-technique/fs-technique-scope-fc/#liste-des-claims | ||
*/ | ||
export const FranceConnectUserInfoSchema = z.object({ | ||
birthdate: z.string(), | ||
birthplace: z.string(), | ||
family_name: z.string(), | ||
gender: z.string(), | ||
given_name: z.string(), | ||
}); | ||
|
||
export type FranceConnectUserInfo = z.infer<typeof FranceConnectUserInfoSchema>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.