Skip to content

Commit

Permalink
Fix the logout button to work with the recent version of `oidc-authse…
Browse files Browse the repository at this point in the history
…rvice` (kubeflow#6609)

* Pin alpine repository version

* Introduce a new LogoutButton component
  • Loading branch information
alembiewski authored and kimwnasptd committed Feb 15, 2023
1 parent 1f6c6aa commit c15c005
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 4 deletions.
4 changes: 2 additions & 2 deletions components/centraldashboard/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ ENV BUILD_COMMIT=$commit
ENV CHROME_BIN=/usr/bin/chromium
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true

RUN apt update -qq && apt install -qq -y chromium gnulib
RUN apt update -qq && apt install -qq -y chromium gnulib

COPY . /centraldashboard
WORKDIR /centraldashboard

RUN BUILDARCH="$(dpkg --print-architecture)" && npm rebuild && \
if [ "$BUILDARCH" = "arm64" ] || \
[ "$BUILDARCH" = "armhf" ]; then \
export CFLAGS=-Wno-error && \
export CFLAGS=-Wno-error && \
export CXXFLAGS=-Wno-error; \
fi && \
npm install && \
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.
* 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';
import {
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 @@ -82,8 +82,7 @@ app-drawer-layout.flex(narrow='{{narrowMode}}',
all-namespaces='[[allNamespaces]]',
user='[[user]]')
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

0 comments on commit c15c005

Please sign in to comment.