Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

Fix logout button #17

Merged
merged 2 commits into from
Jun 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions components/centraldashboard/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true

# Installs latest-stable Chromium package and configures environment for testing
RUN apk update && apk upgrade && \
echo @stable http://nl.alpinelinux.org/alpine/latest-stable/community >> /etc/apk/repositories && \
echo @stable http://nl.alpinelinux.org/alpine/latest-stable/main >> /etc/apk/repositories
echo @stable http://nl.alpinelinux.org/alpine/v3.15/community >> /etc/apk/repositories && \
echo @stable http://nl.alpinelinux.org/alpine/v3.15/main >> /etc/apk/repositories

RUN apk add --no-cache bash chromium@stable nss@stable \
RUN apk add --no-cache bash@stable chromium@stable nss@stable \
freetype@stable \
harfbuzz@stable \
ttf-freefont@stable \
Expand Down
77 changes: 77 additions & 0 deletions components/centraldashboard/public/components/logout-button.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import {html, PolymerElement} from '@polymer/polymer/polymer-element.js';

import '@polymer/iron-ajax/iron-ajax.js';
import '@polymer/paper-button/paper-button.js';

/**
* Logout button component.
* Handles the logout requests and post-logout redirects.
*
*/

export class LogoutButton extends PolymerElement {
static get template() {
return html`
<paper-button id="logout-button" on-tap="logout">
<iron-icon icon='kubeflow:logout' title="Logout"
</iron-icon>
</paper-button>
<iron-ajax
id='logout'
url='/logout'
method='post'
handle-as='json'
headers='{{headers}}'
on-response='_postLogout'>
</iron-ajax>
`;
}

static get properties() {
return {
headers: {
type: Object,
computed: '_setHeaders()',
},
};
}

/**
* After successful logout, redirects user to `afterLogoutURL`,
* received from the backend.
*
* @param {{Event}} event
* @private
*/
_postLogout(event) {
window.location.replace(event.detail.response['afterLogoutURL']);
}

/**
* Call logout endpoint.
*/
logout() {
// call iron-ajax
this.$.logout.generateRequest();
}

/**
* Set 'Authorization' header based on the existing cookie.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking at this page the authservice creates a session cookie.
does the logout button with the suggested change delete this cookie?
meaning... once logged out from one user, can we immediately log in with a new user with no issues?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, a session cookie is removed after the user logs out, it is done via Set-Cookie header: https://github.com/arrikto/oidc-authservice/blob/ae92e8656c5252eddb305f6b9bb72ae1e1e61f6c/session.go#L75

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perfect!

* Currently, the logout method only accepts authorization header, see:
* https://github.com/arrikto/oidc-authservice/blob/master/server.go#L386
*
* @return {{Object}} headers
* @private
*/
_setHeaders() {
const cookie = ('; ' + document.cookie)
.split(`; authservice_session=`)
.pop()
.split(';')[0];
return {
'Authorization': `Bearer ${cookie}`,
};
}
}

customElements.define('logout-button', LogoutButton);
1 change: 1 addition & 0 deletions components/centraldashboard/public/components/main-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import './namespace-needed-view.js';
import './manage-users-view.js';
import './resources/kubeflow-icons.js';
import './iframe-container.js';
import './logout-button.js';
import utilitiesMixin from './utilities-mixin.js';
import {IFRAME_LINK_PREFIX} from './iframe-link.js';

Expand Down
3 changes: 1 addition & 2 deletions components/centraldashboard/public/components/main-page.pug
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ app-drawer-layout.flex(narrow='{{narrowMode}}',
selected='{{namespace}}', hides, hidden$='[[hideNamespaces]]'
all-namespaces='[[allNamespaces]]')
footer#User-Badge
a(target="_top", href="/logout")
iron-icon.icon(icon='kubeflow:logout' title="Logout")
logout-button
main#Content
section#ViewTabs(hidden$='[[hideTabs]]')
paper-tabs(selected='[[page]]', attr-for-selected='page')
Expand Down