wip/authorization-header #7

Merged
radical merged 8 commits from wip/authorization-header into main 2025-05-04 21:18:28 +00:00
2 changed files with 18 additions and 0 deletions
Showing only changes of commit aa865e2ed4 - Show all commits

View file

@ -8,6 +8,7 @@ mod config;
use config::{Config, ConfigBuilder}; use config::{Config, ConfigBuilder};
mod api; mod api;
pub mod crypto; pub mod crypto;
pub mod utils;
type Error = Box<dyn std::error::Error>; type Error = Box<dyn std::error::Error>;

17
src/utils.rs Normal file
View file

@ -0,0 +1,17 @@
use actix_web::{HttpResponse, http::header::HeaderMap};
pub fn get_auth_header(headers: &HeaderMap) -> Result<&str, HttpResponse> {
let auth_token = headers.get(actix_web::http::header::CONTENT_TYPE);
if let None = auth_token {
return Err(HttpResponse::Unauthorized().finish());
}
let auth = auth_token.unwrap().to_str();
if let Err(error) = auth {
return Err(HttpResponse::Unauthorized().json(format!(r#" {{ "error": "{}" }} "#, error)));
}
Ok(auth.unwrap())
}