This commit is contained in:
@@ -6,15 +6,18 @@ use crate::auth::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
pub async fn auth_middleware(mut request: Request, next: Next) -> Result<Response, StatusCode> {
|
pub async fn auth_middleware(mut request: Request, next: Next) -> Result<Response, StatusCode> {
|
||||||
dbg!("Middleware hit");
|
#[cfg(debug_assertions)]
|
||||||
|
println!("Middleware hit");
|
||||||
|
|
||||||
let headers = request.headers();
|
let headers = request.headers();
|
||||||
|
|
||||||
dbg!("Headers extracted");
|
#[cfg(debug_assertions)]
|
||||||
|
println!("Headers extracted");
|
||||||
|
|
||||||
let auth_header = headers.get("authorization").and_then(|v| v.to_str().ok());
|
let auth_header = headers.get("authorization").and_then(|v| v.to_str().ok());
|
||||||
|
|
||||||
dbg!("Auth header: {:?}", auth_header);
|
#[cfg(debug_assertions)]
|
||||||
|
println!("Auth header: {:?}", auth_header);
|
||||||
|
|
||||||
let auth_header = auth_header.ok_or(StatusCode::UNAUTHORIZED)?;
|
let auth_header = auth_header.ok_or(StatusCode::UNAUTHORIZED)?;
|
||||||
|
|
||||||
@@ -26,7 +29,8 @@ pub async fn auth_middleware(mut request: Request, next: Next) -> Result<Respons
|
|||||||
|
|
||||||
match validate_token(token, &jwks) {
|
match validate_token(token, &jwks) {
|
||||||
Ok(claims) => {
|
Ok(claims) => {
|
||||||
dbg!("Token valid");
|
#[cfg(debug_assertions)]
|
||||||
|
println!("Token valid");
|
||||||
|
|
||||||
request.extensions_mut().insert(claims);
|
request.extensions_mut().insert(claims);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user