From 0dbcb8e5fee268dcb97bd79f788488e740e27042 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Poussard?= <tpoussard@neogeo.fr> Date: Thu, 6 Jul 2023 13:23:29 +0200 Subject: [PATCH] get token in url and login user by calling new api endpoint --- src/store/index.js | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/store/index.js b/src/store/index.js index e2d18f63..301cffd9 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -54,7 +54,7 @@ export default new Vuex.Store({ SET_CONFIG(state, payload) { state.configuration = payload; }, - SET_COOKIE(state, cookie) { + SET_COOKIE(state, cookie) { // ! not called anywhere. Delete it ? state.cookie = cookie; }, SET_STATIC_PAGES(state, staticPages) { @@ -175,7 +175,7 @@ export default new Vuex.Store({ } }, - USER_INFO({ state, commit }) { + USER_INFO({ state, commit, dispatch }) { if (!state.user) { axios .get(`${this.state.configuration.VUE_APP_DJANGO_API_BASE}user_info/`) @@ -187,6 +187,7 @@ export default new Vuex.Store({ }) .catch(() => { //* if an url to redirect to an external authentification system is present, do not redirect to the login page + const token = new URLSearchParams(window.location.search).get('token'); if (!state.configuration.VUE_APP_LOGIN_URL) { const url = window.location.href; if (url.includes('projet-partage')) { @@ -195,11 +196,27 @@ export default new Vuex.Store({ } else { router.push({ name: 'login' }); } + } else if (token) { + dispatch('CONNECT_SSO_WITH_TOKEN', token); } }); } }, + async CONNECT_SSO_WITH_TOKEN({commit}, token) { + axios + .get(`${this.state.configuration.VUE_APP_DJANGO_API_BASE}login-token/?token=${token}`) + .then((response) => { + if (response && (response.status === 200 || response.status === 201)) { + const user = response.data; + commit('SET_USER', user); + } + }) + .catch((err) => { + console.error(err); + }) + }, + async GET_USER_TOKEN({ commit }) { const response = await axios.get(`${this.state.configuration.VUE_APP_DJANGO_API_BASE}get-token`); if ( -- GitLab