Skip to content
Snippets Groups Projects
Commit 0dbcb8e5 authored by Timothee P's avatar Timothee P :sunflower:
Browse files

get token in url and login user by calling new api endpoint

parent 4e7c34e3
No related branches found
No related tags found
1 merge request!591REDMINE_ISSUE-17472 | Connexion annuaire MRN WP et GéoContrib
...@@ -54,7 +54,7 @@ export default new Vuex.Store({ ...@@ -54,7 +54,7 @@ export default new Vuex.Store({
SET_CONFIG(state, payload) { SET_CONFIG(state, payload) {
state.configuration = payload; state.configuration = payload;
}, },
SET_COOKIE(state, cookie) { SET_COOKIE(state, cookie) { // ! not called anywhere. Delete it ?
state.cookie = cookie; state.cookie = cookie;
}, },
SET_STATIC_PAGES(state, staticPages) { SET_STATIC_PAGES(state, staticPages) {
...@@ -175,7 +175,7 @@ export default new Vuex.Store({ ...@@ -175,7 +175,7 @@ export default new Vuex.Store({
} }
}, },
USER_INFO({ state, commit }) { USER_INFO({ state, commit, dispatch }) {
if (!state.user) { if (!state.user) {
axios axios
.get(`${this.state.configuration.VUE_APP_DJANGO_API_BASE}user_info/`) .get(`${this.state.configuration.VUE_APP_DJANGO_API_BASE}user_info/`)
...@@ -187,6 +187,7 @@ export default new Vuex.Store({ ...@@ -187,6 +187,7 @@ export default new Vuex.Store({
}) })
.catch(() => { .catch(() => {
//* if an url to redirect to an external authentification system is present, do not redirect to the login page //* 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) { if (!state.configuration.VUE_APP_LOGIN_URL) {
const url = window.location.href; const url = window.location.href;
if (url.includes('projet-partage')) { if (url.includes('projet-partage')) {
...@@ -195,11 +196,27 @@ export default new Vuex.Store({ ...@@ -195,11 +196,27 @@ export default new Vuex.Store({
} else { } else {
router.push({ name: 'login' }); 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 }) { async GET_USER_TOKEN({ commit }) {
const response = await axios.get(`${this.state.configuration.VUE_APP_DJANGO_API_BASE}get-token`); const response = await axios.get(`${this.state.configuration.VUE_APP_DJANGO_API_BASE}get-token`);
if ( if (
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment