-
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.
Merge pull request #6 from sandybemonkey/CLEAN_CODE_AND_REPO
Refactor files structure and do some little fixes
- Loading branch information
Showing
27 changed files
with
6,097 additions
and
454 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
* Helper to get an access token from France Connect. | ||
* @see @link{ https://partenaires.franceconnect.gouv.fr/fcp/fournisseur-service# } | ||
*/ | ||
import axios from 'axios'; | ||
import querystring from 'querystring'; | ||
import getUser from '../helpers/user'; | ||
import config from '../config/config.json'; | ||
|
||
const tokenUrl = config.TOKEN_URL; | ||
const redirectUrl = config.REDIRECT_URL; | ||
const clientId = config.CLIENT_SECRET; | ||
const secretKey = config.SECRET_KEY; | ||
|
||
/** | ||
* Init FranceConnect authentication login process. | ||
* Make every http call to the different API endpoints. | ||
*/ | ||
const getAccessToken = async (res, req) => { | ||
// Set request params. | ||
const url = tokenUrl; | ||
const body = { | ||
grant_type: 'authorization_code', | ||
redirect_uri: redirectUrl, | ||
client_id: clientId, | ||
client_secret: secretKey, | ||
code: req.query.code, | ||
}; | ||
const headerConfig = { | ||
headers: { | ||
'Content-Type': 'application/x-www-form-urlencoded', | ||
}, | ||
}; | ||
|
||
// Request access token. | ||
await axios.post(url, querystring.stringify(body), headerConfig) | ||
.then(response => response.data) | ||
.then((tokenData) => { | ||
req.accessToken = tokenData.access_token; | ||
req.session.id_token = tokenData.id_token; | ||
// Make a call to the France Connect API endpoint to get user data. | ||
getUser(req, res); | ||
}) | ||
.catch(err => res.send(err.message)); | ||
}; | ||
|
||
export default getAccessToken; |
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,43 @@ | ||
/** | ||
* Use to send the access token to an data provider. | ||
* @return Response with the queried data from the provider. | ||
* @see @link{ https://partenaires.franceconnect.gouv.fr/fcp/fournisseur-donnees } | ||
* @see @link{ https://github.com/france-connect/data-providers-examples } | ||
*/ | ||
import axios from 'axios/index'; | ||
import config from '../config/config.json'; | ||
|
||
const fdMockUrl = config.FD_MOCK_URL; | ||
// this value is only for a demo purpose you should use the Access token send by FC | ||
const fakeAccessToken = '9af033eb295d0fe113988d29a26527f920114973b3a1ca7bdb44768fd0c73937'; | ||
|
||
const getFDData = (req, res) => { | ||
axios({ | ||
method: 'GET', | ||
/** | ||
* only valid used with dat-providers-example code from France Connect repo. | ||
* If use using your code change the url's value. | ||
*/ | ||
url: fdMockUrl, | ||
headers: { Authorization: `Bearer ${fakeAccessToken}` }, | ||
}) | ||
.then((fdResponse) => { | ||
const isFdData = true; | ||
const isAuth = true; | ||
const user = req.session.userInfo; | ||
const dgfipData = []; | ||
const responsedata = fdResponse.data; | ||
|
||
for (const property in responsedata) { | ||
if (property !== null) { | ||
dgfipData[property] = fdResponse.data[property]; | ||
} | ||
} | ||
res.render('pages/profile', { | ||
user, isAuth, isFdData, dgfipData, | ||
}); | ||
}) | ||
.catch(err => res.send(err.message)); | ||
}; | ||
|
||
export default getFDData; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
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 was deleted.
Oops, something went wrong.
Oops, something went wrong.