-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ouvre route
GET /auth/fcplus/creationSession
Étapes suivantes : - gérer le cas `idp_hint=eidas-bridge` avec variable environnement - ajouter un lien « se connecter » sur la page d'accueil - ajouter les nouveaux points d'entrée dans le serveur mock FC+ - `authorization_endpoint` Puis plus tard… - regarder s'il ne faut pas ajouter des `return` dans les tests de `test/api/destructionSessionFCPlus.spec.js` - factoriser adaptateurChiffrement.clefHachage(`${Math.random()}`) Co-authored-by: Emmanuel Gaillot <[email protected]>
- Loading branch information
Showing
9 changed files
with
169 additions
and
0 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
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,15 @@ | ||
const creationSessionFCPlus = (config, requete, reponse) => { | ||
const { adaptateurChiffrement, adaptateurEnvironnement, adaptateurFranceConnectPlus } = config; | ||
|
||
const identifiantClient = adaptateurEnvironnement.identifiantClient(); | ||
const urlRedirectionConnexion = adaptateurEnvironnement.urlRedirectionConnexion(); | ||
const etat = adaptateurChiffrement.cleHachage(`${Math.random()}`); | ||
const nonce = adaptateurChiffrement.cleHachage(`${Math.random()}`); | ||
|
||
return adaptateurFranceConnectPlus.urlCreationSession() | ||
.then((url) => reponse.redirect( | ||
`${url}?scope=profile%20openid&acr_values=eidas2&claims={%22id_token%22:{%22amr%22:{%22essential%22:true}}}&prompt=login%20consent&response_type=code&client_id=${identifiantClient}&redirect_uri=${urlRedirectionConnexion}&state=${etat}&nonce=${nonce}`, | ||
)); | ||
}; | ||
|
||
module.exports = creationSessionFCPlus; |
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
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,110 @@ | ||
const creationSessionFCPlus = require('../../src/api/creationSessionFCPlus'); | ||
|
||
describe('Le requêteur de création de session FC+', () => { | ||
const adaptateurChiffrement = {}; | ||
const adaptateurEnvironnement = {}; | ||
const adaptateurFranceConnectPlus = {}; | ||
const config = { adaptateurChiffrement, adaptateurEnvironnement, adaptateurFranceConnectPlus }; | ||
const reponse = {}; | ||
|
||
const requete = {}; | ||
|
||
beforeEach(() => { | ||
adaptateurChiffrement.cleHachage = () => ''; | ||
adaptateurEnvironnement.identifiantClient = () => ''; | ||
adaptateurEnvironnement.urlRedirectionConnexion = () => ''; | ||
adaptateurFranceConnectPlus.urlCreationSession = () => Promise.resolve(''); | ||
}); | ||
|
||
it('redirige vers serveur France Connect Plus', () => { | ||
expect.assertions(1); | ||
adaptateurFranceConnectPlus.urlCreationSession = () => Promise.resolve('http://example.com'); | ||
|
||
reponse.redirect = (url) => { | ||
try { | ||
expect(url).toMatch(/^http:\/\/example\.com\?/); | ||
return Promise.resolve(); | ||
} catch (e) { | ||
return Promise.reject(e); | ||
} | ||
}; | ||
|
||
return creationSessionFCPlus(config, requete, reponse); | ||
}); | ||
|
||
it('ajoute des paramètres à la requête', () => { | ||
expect.assertions(5); | ||
|
||
reponse.redirect = (url) => { | ||
try { | ||
expect(url).toContain('scope=profile%20openid'); | ||
expect(url).toContain('acr_values=eidas2'); | ||
expect(url).toContain('claims={%22id_token%22:{%22amr%22:{%22essential%22:true}}}'); | ||
expect(url).toContain('prompt=login%20consent'); | ||
expect(url).toContain('response_type=code'); | ||
|
||
return Promise.resolve(); | ||
} catch (e) { | ||
return Promise.reject(e); | ||
} | ||
}; | ||
|
||
return creationSessionFCPlus(config, requete, reponse); | ||
}); | ||
|
||
it("ajoute l'identifiant client FC+ en paramètre", () => { | ||
expect.assertions(1); | ||
|
||
adaptateurEnvironnement.identifiantClient = () => '12345'; | ||
|
||
reponse.redirect = (url) => { | ||
try { | ||
expect(url).toContain('client_id=12345'); | ||
return Promise.resolve(); | ||
} catch (e) { | ||
return Promise.reject(e); | ||
} | ||
}; | ||
|
||
return creationSessionFCPlus(config, requete, reponse); | ||
}); | ||
|
||
it("ajoute l'URL de redirection post-login en paramètre", () => { | ||
expect.assertions(1); | ||
|
||
adaptateurEnvironnement.urlRedirectionConnexion = () => 'http://example.com'; | ||
|
||
reponse.redirect = (url) => { | ||
try { | ||
expect(url).toContain('redirect_uri=http://example.com'); | ||
return Promise.resolve(); | ||
} catch (e) { | ||
return Promise.reject(e); | ||
} | ||
}; | ||
|
||
return creationSessionFCPlus(config, requete, reponse); | ||
}); | ||
|
||
it('ajoute un état et un nonce en paramètres de la requête', () => { | ||
expect.assertions(2); | ||
let nbClesGenerees = 0; | ||
|
||
adaptateurChiffrement.cleHachage = () => { | ||
nbClesGenerees += 1; | ||
return `12345-${nbClesGenerees}`; | ||
}; | ||
|
||
reponse.redirect = (url) => { | ||
try { | ||
expect(url).toContain('state=12345-1'); | ||
expect(url).toContain('nonce=12345-2'); | ||
return Promise.resolve(); | ||
} catch (e) { | ||
return Promise.reject(e); | ||
} | ||
}; | ||
|
||
return creationSessionFCPlus(config, requete, reponse); | ||
}); | ||
}); |
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