diff --git a/components/centraldashboard/public/components/main-page.css b/components/centraldashboard/public/components/main-page.css index 78f20988e8a..6c0aeb6e67e 100644 --- a/components/centraldashboard/public/components/main-page.css +++ b/components/centraldashboard/public/components/main-page.css @@ -248,15 +248,20 @@ neon-animatable { height: 100%; } -#User-Badge { +#LogoutButton { right: 16px; position: absolute; } -#User-Badge .icon { +#LogoutButton .icon { color: var(--primary-background-color); } +#LogoutButton .icon:hover { + color: var(--accent-color); + cursor: pointer; +} + #Menu { --paper-icon-button: { width: 44px; diff --git a/components/centraldashboard/public/components/main-page.js b/components/centraldashboard/public/components/main-page.js index edc30173985..809678caabd 100644 --- a/components/centraldashboard/public/components/main-page.js +++ b/components/centraldashboard/public/components/main-page.js @@ -98,6 +98,7 @@ export class MainPage extends utilitiesMixin(PolymerElement) { }, namespaces: Array, namespace: String, + logoutUrl: {type: String, value: '/authservice/logout'}, user: String, isClusterAdmin: {type: Boolean, value: false}, isolationMode: {type: String, value: 'undecided', readOnly: true}, @@ -232,9 +233,6 @@ export class MainPage extends utilitiesMixin(PolymerElement) { let hideSidebar = false; switch (newPage) { - case 'logout': - window.top.location.href = '/logout'; - break; case 'activity': this.page = 'activity'; hideTabs = false; @@ -427,6 +425,42 @@ export class MainPage extends utilitiesMixin(PolymerElement) { // trigger template render this.menuLinks = JSON.parse(JSON.stringify(this.menuLinks)); } + + async logout() { + this.$.Logout.headers['Authorization'] = 'Bearer ' + + this._getAuthorizationHeader(); + const req = await this.$.Logout.generateRequest(); + await req.completes; + // eslint-disable-next-line no-console + console.log(req); + if (!req.succeeded) { + // eslint-disable-next-line no-console + console.log('Logout request failed'); + } + if (req.response && req.response.afterLogoutURL) { + window.location.replace(req.response.afterLogoutURL); + } + } + + _getAuthorizationHeader() { + const session = this._getCookie('authservice_session'); + return session; + } + + _getCookie(cname) { + const name = cname + '='; + const ca = document.cookie.split(';'); + for (let i = 0; i < ca.length; i++) { + let c = ca[i]; + while (c.charAt(0) == ' ') { + c = c.substring(1); + } + if (c.indexOf(name) == 0) { + return c.substring(name.length, c.length); + } + } + return ''; + } } window.customElements.define('main-page', MainPage); diff --git a/components/centraldashboard/public/components/main-page.pug b/components/centraldashboard/public/components/main-page.pug index 5e7cfc05bb4..85c302d2801 100644 --- a/components/centraldashboard/public/components/main-page.pug +++ b/components/centraldashboard/public/components/main-page.pug @@ -4,6 +4,7 @@ iron-ajax(auto, url='/api/dashboard-links', handle-as='json', on-response='_onHasDashboardLinksResponse', on-error='_onHasDashboardLinksError', loading='{{pageLoading}}') iron-ajax#envInfo(auto='[[_shouldFetchEnv]]', url='/api/workgroup/env-info', handle-as='json', on-response='_onEnvInfoResponse') +iron-ajax#Logout(method="POST", url='[[logoutUrl]]', handle-as='json') aside#PageLoader(hidden='{{!pageLoading}}') app-drawer-layout.flex(narrow='{{narrowMode}}', force-narrow='[[or(thinView, hideSidebar)]]', @@ -79,8 +80,8 @@ app-drawer-layout.flex(narrow='{{narrowMode}}', query-params='{{queryParams}}', namespaces='[[namespaces]]' selected='{{namespace}}', hides, hidden$='[[hideNamespaces]]' all-namespaces='[[allNamespaces]]') - footer#User-Badge - a(target="_top", href="/logout") + footer#LogoutButton + a(target="_top", on-click='logout') iron-icon.icon(icon='kubeflow:logout' title="Logout") main#Content section#ViewTabs(hidden$='[[hideTabs]]')