Cleanup spa handling (#1825)

This commit is contained in:
Firstyear 2023-07-08 16:37:15 +10:00 committed by GitHub
parent 8e1e533f40
commit 72bca853f7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 1 deletions

View file

@ -603,7 +603,35 @@ pub async fn oauth2_openid_discovery_get(
.qe_r_ref
.handle_oauth2_openid_discovery(client_id, kopid.eventid)
.await;
to_axum_response(res)
match res {
Ok(dsc) => {
// Humans may look at this so we pretty it.
#[allow(clippy::unwrap_used)]
let body = serde_json::to_string_pretty(&dsc).unwrap();
#[allow(clippy::unwrap_used)]
Response::builder()
.status(StatusCode::OK)
.header(ACCESS_CONTROL_ALLOW_ORIGIN, "*")
.body(Body::from(body))
.unwrap()
}
Err(e) => {
error!(err = ?e, "Unable to access discovery info");
let body = match serde_json::to_string(&e) {
Ok(val) => val,
Err(e) => {
format!("{:?}", e)
}
};
#[allow(clippy::unwrap_used)]
Response::builder()
.status(StatusCode::BAD_REQUEST)
.header(ACCESS_CONTROL_ALLOW_ORIGIN, "*")
.body(Body::from(body))
.unwrap()
}
}
}
pub async fn oauth2_openid_userinfo_get(

View file

@ -151,6 +151,13 @@ impl Oauth2App {
.set("content-type", "application/json")
.expect_throw("failed to set header");
if let Some(bearer_token) = models::get_bearer_token() {
request
.headers()
.set("authorization", &bearer_token)
.expect_throw("failed to set authorisation header");
}
let window = utils::window();
let resp_value = JsFuture::from(window.fetch_with_request(&request)).await?;
let resp: Response = resp_value.dyn_into().expect_throw("Invalid response type");