extra debugging
This commit is contained in:
parent
22fb586c77
commit
1423d995a4
1 changed files with 44 additions and 9 deletions
|
|
@ -111,29 +111,64 @@ pub fn generate_password(pid: i32, cleartext_password: &str) -> Option<String>{
|
||||||
|
|
||||||
|
|
||||||
pub async fn read_basic_auth_token(connection: &Pool, token: &str) -> Option<User> {
|
pub async fn read_basic_auth_token(connection: &Pool, token: &str) -> Option<User> {
|
||||||
let data = BASE64_STANDARD.decode(&token).ok()?;
|
println!("Received token (base64): {:?}", token);
|
||||||
|
|
||||||
let decoded_basic_token = String::from_utf8(data).ok()?;
|
let data = match BASE64_STANDARD.decode(&token) {
|
||||||
|
Ok(d) => d,
|
||||||
|
Err(e) => {
|
||||||
|
println!("Failed to decode base64: {:?}", e);
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
println!("Decoded base64 bytes: {:?}", data);
|
||||||
|
|
||||||
let (login_username, login_password) = decoded_basic_token.split_once(' ')?;
|
let decoded_basic_token = match String::from_utf8(data) {
|
||||||
|
Ok(s) => s,
|
||||||
|
Err(e) => {
|
||||||
|
println!("Failed to convert decoded bytes to UTF-8 string: {:?}", e);
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
println!("Decoded basic auth token string: {:?}", decoded_basic_token);
|
||||||
|
|
||||||
|
let (login_username, login_password) = match decoded_basic_token.split_once(' ') {
|
||||||
|
Some(parts) => parts,
|
||||||
|
None => {
|
||||||
|
println!("Failed to split basic token into username and password");
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
println!("Parsed login_username: {:?}", login_username);
|
||||||
|
println!("Parsed login_password: {:?}", login_password);
|
||||||
|
|
||||||
|
let user_result = sqlx::query_as!(
|
||||||
let mut user = sqlx::query_as!(
|
|
||||||
User,
|
User,
|
||||||
"SELECT * FROM users WHERE username = $1",
|
"SELECT * FROM users WHERE username = $1",
|
||||||
login_username
|
login_username
|
||||||
).fetch_one(connection).await.ok()?;
|
).fetch_one(connection).await;
|
||||||
|
|
||||||
|
let mut user = match user_result {
|
||||||
|
Ok(u) => u,
|
||||||
|
Err(e) => {
|
||||||
|
println!("Failed to fetch user from database: {:?}", e);
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
println!("Fetched user from database: {:?}", user);
|
||||||
|
|
||||||
let password_valid = user.verify_cleartext_password(&login_password);
|
let password_valid = user.verify_cleartext_password(&login_password);
|
||||||
|
println!("Password verification result: {:?}", password_valid);
|
||||||
|
|
||||||
if password_valid == Some(true) {
|
if password_valid == Some(true) {
|
||||||
|
println!("Password verification succeeded");
|
||||||
Some(user)
|
Some(user)
|
||||||
} else {
|
} else {
|
||||||
|
println!("Password verification failed");
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub async fn read_bearer_auth_token(connection: &Pool, token: &str) -> Option<User> {
|
pub async fn read_bearer_auth_token(connection: &Pool, token: &str) -> Option<User> {
|
||||||
let data = TokenData::decode(token)?;
|
let data = TokenData::decode(token)?;
|
||||||
|
|
||||||
|
|
@ -208,11 +243,11 @@ impl<'r, const FORCE_BEARER_AUTH: bool> FromRequest<'r> for Auth<FORCE_BEARER_AU
|
||||||
let user = match auth_type{
|
let user = match auth_type{
|
||||||
"Basic" if !FORCE_BEARER_AUTH => read_basic_auth_token(pool, token).await,
|
"Basic" if !FORCE_BEARER_AUTH => read_basic_auth_token(pool, token).await,
|
||||||
"Bearer" => read_bearer_auth_token(pool, token).await,
|
"Bearer" => read_bearer_auth_token(pool, token).await,
|
||||||
_ => return Outcome::Error((Status::BadRequest, INVALID_TOKEN_ERRORS_DBG)),
|
_ => return Outcome::Error((Status::BadRequest, INVALID_TOKEN_ERRORS)),
|
||||||
};
|
};
|
||||||
|
|
||||||
let Some(user) = user else {
|
let Some(user) = user else {
|
||||||
return Outcome::Error((Status::BadRequest, INVALID_TOKEN_ERRORS));
|
return Outcome::Error((Status::BadRequest, INVALID_TOKEN_ERRORS_DBG));
|
||||||
};
|
};
|
||||||
|
|
||||||
Outcome::Success(Self(user))
|
Outcome::Success(Self(user))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue