fix: add more debug logs

This commit is contained in:
Matthieu Bessat 2025-06-24 18:46:01 +02:00
parent fdb868d10c
commit 18b33c00a7
2 changed files with 6 additions and 4 deletions

View file

@ -1,7 +1,7 @@
use axum::{extract::State, http::StatusCode, response::{Html, IntoResponse}, Extension, Form, Json}; use axum::{extract::State, http::StatusCode, response::{Html, IntoResponse}, Extension, Form, Json};
use chrono::{Duration, Utc}; use chrono::{Duration, Utc};
use fully_pub::fully_pub; use fully_pub::fully_pub;
use log::error; use log::{debug, error};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use kernel::{models::authorization::Authorization, repositories::users::get_user_by_id}; use kernel::{models::authorization::Authorization, repositories::users::get_user_by_id};
@ -11,7 +11,7 @@ use crate::{
const AUTHORIZATION_CODE_TTL_SECONDS: i64 = 120; const AUTHORIZATION_CODE_TTL_SECONDS: i64 = 120;
#[derive(Serialize, Deserialize)] #[derive(Serialize, Deserialize, Debug)]
#[fully_pub] #[fully_pub]
struct AccessTokenRequestParams { struct AccessTokenRequestParams {
grant_type: String, grant_type: String,
@ -48,6 +48,7 @@ pub async fn get_access_token(
let authorization = match authorizations_res { let authorization = match authorizations_res {
Ok(val) => val, Ok(val) => val,
Err(sqlx::Error::RowNotFound) => { Err(sqlx::Error::RowNotFound) => {
error!("Received invalid authorization_code.");
return ( return (
StatusCode::BAD_REQUEST, StatusCode::BAD_REQUEST,
Json("Invalid authorization_code.") Json("Invalid authorization_code.")
@ -68,12 +69,15 @@ pub async fn get_access_token(
Utc::now().signed_duration_since(ts) < Duration::seconds(AUTHORIZATION_CODE_TTL_SECONDS) Utc::now().signed_duration_since(ts) < Duration::seconds(AUTHORIZATION_CODE_TTL_SECONDS)
}); });
if !is_code_valid { if !is_code_valid {
debug!("Received expired authorization code");
return ( return (
StatusCode::BAD_REQUEST, StatusCode::BAD_REQUEST,
Json("Authorization code has expired.") Json("Authorization code has expired.")
).into_response(); ).into_response();
} }
debug!("Generating access_token and id_token.");
// 2.3. Fetch user resource owner // 2.3. Fetch user resource owner
let user = get_user_by_id(&app_state.db, &authorization.user_id) let user = get_user_by_id(&app_state.db, &authorization.user_id)
.await .await

View file

@ -1,5 +1,3 @@
use std::str::FromStr;
use jsonwebkey_convert_repaired::RSAPublicKey; use jsonwebkey_convert_repaired::RSAPublicKey;
use jsonwebkey_convert_repaired::der::FromPem; use jsonwebkey_convert_repaired::der::FromPem;