kych

OAuth 2.0 API for Swiyu to enable Taler integration of Swiyu for KYC (experimental)
Log | Files | Refs

commit 80b72aa6968330a0a27421e8786faf411c8fafa6
parent 4360a128c4a6715b32ca1470bd3f4be23cd5e80f
Author: Henrique Chan Carvalho Machado <henriqueccmachado@tecnico.ulisboa.pt>
Date:   Tue,  9 Dec 2025 13:02:33 +0100

oauth2_gateway: fix json pretty response in /authorize

Diffstat:
Moauth2_gateway/src/handlers.rs | 30++++++++++++------------------
Moauth2_gateway/src/models.rs | 25+++++++++++++++++++++++++
2 files changed, 37 insertions(+), 18 deletions(-)

diff --git a/oauth2_gateway/src/handlers.rs b/oauth2_gateway/src/handlers.rs @@ -189,15 +189,12 @@ pub async fn authorize( .and_then(|id| uuid::Uuid::parse_str(&id).ok()) .unwrap_or(uuid::Uuid::nil()); - return Ok(( - StatusCode::OK, - Json(AuthorizeResponse { - verification_id, - verification_url: data.verification_url.clone().unwrap_or_default(), - verification_deeplink: data.verification_deeplink, - state: params.state.clone() - }), - )); + return Ok(PrettyJson(AuthorizeResponse { + verification_id, + verification_url: data.verification_url.clone().unwrap_or_default(), + verification_deeplink: data.verification_deeplink, + state: params.state.clone() + })); } SessionStatus::Pending => { @@ -296,15 +293,12 @@ pub async fn authorize( swiyu_response.id ); - Ok(( - StatusCode::OK, - Json(AuthorizeResponse { - verification_id: swiyu_response.id, - verification_url: result.verification_url, - verification_deeplink: swiyu_response.verification_deeplink, - state: params.state.clone() - }), - )) + Ok(PrettyJson(AuthorizeResponse { + verification_id: swiyu_response.id, + verification_url: result.verification_url, + verification_deeplink: swiyu_response.verification_deeplink, + state: params.state.clone() + })) } /// Build a presentation definition from a space-delimited scope string diff --git a/oauth2_gateway/src/models.rs b/oauth2_gateway/src/models.rs @@ -1,6 +1,31 @@ use serde::{Deserialize, Serialize}; use uuid::Uuid; use std::collections::HashMap; +use axum::{ + response::{IntoResponse, Response}, + http::{StatusCode, header}, +}; + +pub struct PrettyJson<T>(pub T); + +impl<T> IntoResponse for PrettyJson<T> +where + T: Serialize, +{ + fn into_response(self) -> Response { + match serde_json::to_string_pretty(&self.0) { + Ok(json) => ( + StatusCode::OK, + [(header::CONTENT_TYPE, "application/json")], + json, + ).into_response(), + Err(e) => ( + StatusCode::INTERNAL_SERVER_ERROR, + format!("Serialization error: {}", e), + ).into_response(), + } + } +} #[derive(Debug, Deserialize, Serialize)] pub struct SetupResponse {