This repository has been archived by the owner on Oct 23, 2024. It is now read-only.
forked from kubeflow/kubeflow
-
Notifications
You must be signed in to change notification settings - Fork 0
Fix logout button #17
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
components/centraldashboard/public/components/logout-button.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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#L75There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perfect!