Skip to content

Commit

Permalink
[post_logout] fix state etc using form (#690)
Browse files Browse the repository at this point in the history
* add state field to html template and pass thgough for logout

* Revert "add state field to html template and pass thgough for logout"

This reverts commit 9c2c807.

* use From for post_logout

* try to get redirect from header location

* redirect using custom header loc instead of LOCATION

* redirect using LOCATION and status OK 200

* shorten code

* use location.replace

---------

Co-authored-by: local <[email protected]>
  • Loading branch information
cocoon and local authored Jan 13, 2025
1 parent 04e28c9 commit c0de5b6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
6 changes: 3 additions & 3 deletions frontend/src/routes/oidc/logout/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@
async function handleRes(res) {
purgeStorage();
if (res.ok) {
window.location.href = res.headers.get('location');
} else {
if (res.ok && res.headers.get('location')) {
window.location.replace(res.headers.get('location'));
}else {
await handleCancel();
}
}
Expand Down
11 changes: 9 additions & 2 deletions frontend/src/utils/dataFetching.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ function getCsrfHeaders() {
}
}

function getCsrfHeadersForm() {
return {
...HEADERS.form,
'csrf-token': getCsrfToken(),
}
}

export async function authorize(data) {
const res = await fetch('/auth/v1/oidc/authorize', {
method: 'POST',
Expand Down Expand Up @@ -87,14 +94,14 @@ export async function getSessionInfoXsrf(accessToken) {
}

export async function logout(data) {
let body = new FormData();
let body = new URLSearchParams();
for (let key in data) {
body.append(key, data[key]);
}

return await fetch('/auth/v1/oidc/logout', {
method: 'POST',
headers: getCsrfHeaders(),
headers: getCsrfHeadersForm(),
body,
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/api/src/oidc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ pub async fn get_logout(
)]
#[post("/oidc/logout")]
pub async fn post_logout(
Query(params): Query<LogoutRequest>,
Form(params): Form<LogoutRequest>,
principal: ReqPrincipal,
) -> Result<HttpResponse, ErrorResponse> {
let session = principal.get_session()?.clone();
Expand All @@ -683,7 +683,7 @@ pub async fn post_logout(
params.post_logout_redirect_uri.as_ref().unwrap(),
state
);
return Ok(HttpResponse::build(StatusCode::MOVED_PERMANENTLY)
return Ok(HttpResponse::build(StatusCode::OK)
.append_header((header::LOCATION, loc))
.cookie(cookie)
.cookie(cookie_fed_cm)
Expand Down

0 comments on commit c0de5b6

Please sign in to comment.