-
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.
:feat remplacement d'inclusion connect par pro connect
- Loading branch information
Showing
8 changed files
with
157 additions
and
102 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
const htaccessContent = ` | ||
RewriteEngine On | ||
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR] | ||
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d | ||
RewriteRule ^ - [L] | ||
RewriteRule ^ /index.html | ||
`; | ||
|
||
const distPath = path.join(__dirname, 'dist'); | ||
const htaccessPath = path.join(distPath, '.htaccess'); | ||
|
||
fs.writeFileSync(htaccessPath, htaccessContent.trim()); |
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,30 @@ | ||
import axios from 'axios'; | ||
|
||
/** | ||
* Gère le processus de connexion ProConnect | ||
* @param {string} verificationToken - Le jeton de vérification pour le processus de connexion | ||
* @param {function} setLoading - Fonction pour définir l'état de chargement | ||
* @param {function} setNetworkError - Fonction pour définir l'état d'erreur réseau | ||
* @returns {Promise<void>} | ||
*/ | ||
export async function handleProConnectLogin(verificationToken, setLoading, setNetworkError) { | ||
const nonce = Math.random().toString(36).substring(7); | ||
const state = Math.random().toString(36).substring(7); | ||
localStorage.setItem('nonce', nonce); | ||
localStorage.setItem('state', state); | ||
setLoading(true); | ||
try { | ||
const response = await axios.post(`${import.meta.env.VITE_APP_API_URL}/create-url`, { | ||
verificationToken, | ||
nonce, | ||
state, | ||
}); | ||
if (response.data) { | ||
window.location.href = response.data.authorizationUrl; | ||
} | ||
} catch (error) { | ||
setNetworkError(true); | ||
} finally { | ||
setLoading(false); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,56 +1,23 @@ | ||
import axios from 'axios'; | ||
import { authenticationActions } from '../../actions'; | ||
import apiUrlRoot from '../../helpers/apiUrl'; | ||
import { UserManager, WebStorageStateStore } from 'oidc-client-ts'; | ||
|
||
const userManager = new UserManager({ | ||
authority: import.meta.env.VITE_APP_AUTH_OIDC_AUTHORITY, | ||
client_id: import.meta.env.VITE_APP_AUTH_CLIENT_ID, | ||
client_secret: import.meta.env.VITE_APP_AUTH_CLIENT_SECRET, | ||
post_logout_redirect_uri: `${import.meta.env.VITE_APP_AUTH_REDIRECT_URI}/passerelle`, | ||
userStore: new WebStorageStateStore({ store: window.localStorage }), | ||
}); | ||
|
||
|
||
const getProfile = () => | ||
JSON.parse( | ||
localStorage.getItem( | ||
import.meta.env.VITE_APP_AUTH_OIDC_USER_KEY | ||
) | ||
); | ||
|
||
const getVerificationToken = () => window.location.pathname.split('/').pop(); | ||
|
||
const signInCallBack = async store => { | ||
const { dispatch } = store; | ||
window.history.replaceState({}, document.title, window.location.pathname); | ||
const profile = getProfile(); | ||
const verificationToken = getVerificationToken(); | ||
const token = profile?.access_token; | ||
dispatch({ type: 'LOGIN_REQUEST' }); | ||
await axios | ||
.get(`${apiUrlRoot}/login`, { | ||
params: { | ||
verificationToken | ||
}, | ||
withCredentials: true, | ||
headers: { | ||
'Access-Control-Allow-Origin': `${apiUrlRoot}/login`, | ||
'Authorization': `Bearer ${token}`, | ||
}, | ||
}) | ||
.then(result => { | ||
dispatch(authenticationActions.login(result?.data)); | ||
dispatch(authenticationActions.refreshToken(result?.data?.accessToken)); | ||
localStorage.setItem('user', JSON.stringify(result?.data)); | ||
localStorage.setItem('roleActivated', result?.data?.user?.roles[0]); | ||
}) | ||
.catch(async error => { | ||
const signInCallBack = async (dispatch, code, state, verificationToken) => { | ||
try { | ||
dispatch({ type: 'LOGIN_REQUEST' }); | ||
const reponse = await axios.post(import.meta.env.VITE_APP_API_URL + '/login', { code, state }, { params: { verificationToken } }); | ||
if (reponse?.data?.accessToken) { | ||
dispatch(authenticationActions.login(reponse?.data)); | ||
dispatch(authenticationActions.refreshToken(reponse?.data?.accessToken)); | ||
localStorage.setItem('user', JSON.stringify(reponse?.data)); | ||
localStorage.setItem('roleActivated', reponse?.data?.user?.roles[0]); | ||
return { success: true }; | ||
} | ||
} catch (error) { | ||
localStorage.setItem('loginError', JSON.stringify(error?.response?.data ?? 'Connexion refusée')); | ||
userManager.signoutRedirect(); | ||
localStorage.removeItem('user'); | ||
dispatch({ type: 'LOGIN_FAILURE' }); | ||
}); | ||
return { success: false }; | ||
} | ||
}; | ||
|
||
export default signInCallBack; |
Large diffs are not rendered by default.
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