From 4a2e63db1734427ae2230eff0f692701efa7248b Mon Sep 17 00:00:00 2001 From: Rohit Yadav Date: Wed, 19 Feb 2020 11:09:44 +0530 Subject: [PATCH] permission: fix cookie handling to allow saml to work Signed-off-by: Rohit Yadav --- ui/src/permission.js | 5 +++++ ui/src/store/modules/user.js | 20 ++++++++++---------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/ui/src/permission.js b/ui/src/permission.js index 04e092596c0..3216a4d32b0 100644 --- a/ui/src/permission.js +++ b/ui/src/permission.js @@ -15,6 +15,7 @@ // specific language governing permissions and limitations // under the License. +import Cookies from 'js-cookie' import Vue from 'vue' import router from './router' import store from './store' @@ -33,6 +34,10 @@ router.beforeEach((to, from, next) => { // start progress bar NProgress.start() to.meta && (typeof to.meta.title !== 'undefined' && setDocumentTitle(`${to.meta.title} - ${domTitle}`)) + const sessionKeyCookie = Cookies.get('sessionkey') + if (sessionKeyCookie && !Vue.ls.get(ACCESS_TOKEN)) { + Vue.ls.set(ACCESS_TOKEN, sessionKeyCookie, 24 * 60 * 60 * 1000) + } if (Vue.ls.get(ACCESS_TOKEN)) { if (to.path === '/user/login') { next({ path: '/dashboard' }) diff --git a/ui/src/store/modules/user.js b/ui/src/store/modules/user.js index be0e9636fd2..b2482a482c8 100644 --- a/ui/src/store/modules/user.js +++ b/ui/src/store/modules/user.js @@ -85,17 +85,17 @@ const user = { login(userInfo).then(response => { const result = response.loginresponse || {} - Cookies.set('account', result.account) - Cookies.set('domainid', result.domainid) - Cookies.set('role', result.type) - Cookies.set('sessionkey', result.sessionkey) - Cookies.set('timezone', result.timezone) - Cookies.set('timezoneoffset', result.timezoneoffset) - Cookies.set('userfullname', result.firstname + ' ' + result.lastname) - Cookies.set('userid', result.userid) - Cookies.set('username', result.username) + Cookies.set('account', result.account, { expires: 1 }) + Cookies.set('domainid', result.domainid, { expires: 1 }) + Cookies.set('role', result.type, { expires: 1 }) + Cookies.set('sessionkey', result.sessionkey, { expires: 1 }) + Cookies.set('timezone', result.timezone, { expires: 1 }) + Cookies.set('timezoneoffset', result.timezoneoffset, { expires: 1 }) + Cookies.set('userfullname', result.firstname + ' ' + result.lastname, { expires: 1 }) + Cookies.set('userid', result.userid, { expires: 1 }) + Cookies.set('username', result.username, { expires: 1 }) - Vue.ls.set(ACCESS_TOKEN, result.sessionkey, 60 * 60 * 1000) + Vue.ls.set(ACCESS_TOKEN, result.sessionkey, 24 * 60 * 60 * 1000) commit('SET_TOKEN', result.sessionkey) commit('SET_PROJECT', {}) commit('SET_ASYNC_JOB_IDS', [])