-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix the logout button to work with the recent version of `oidc-authse…
…rvice` (#6609) * Pin alpine repository version * Introduce a new LogoutButton component
- Loading branch information
1 parent
65e41bf
commit 74f020e
Showing
4 changed files
with
81 additions
and
4 deletions.
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