From 74f80d5c11d0a212a545f053bfd4ca160bcedcd8 Mon Sep 17 00:00:00 2001 From: Owen Jacobson Date: Wed, 19 Feb 2025 21:22:03 -0500 Subject: Upgrade Axum to 0.8.1. --- src/token/extract/identity.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'src/token/extract/identity.rs') diff --git a/src/token/extract/identity.rs b/src/token/extract/identity.rs index a69f509..acfd7ae 100644 --- a/src/token/extract/identity.rs +++ b/src/token/extract/identity.rs @@ -1,5 +1,5 @@ use axum::{ - extract::{FromRequestParts, State}, + extract::{FromRequestParts, OptionalFromRequestParts, State}, http::request::Parts, response::{IntoResponse, Response}, }; @@ -20,7 +20,6 @@ pub struct Identity { pub login: Login, } -#[async_trait::async_trait] impl FromRequestParts for Identity { type Rejection = LoginError; @@ -39,6 +38,21 @@ impl FromRequestParts for Identity { } } +impl OptionalFromRequestParts for Identity { + type Rejection = LoginError; + + async fn from_request_parts( + parts: &mut Parts, + state: &App, + ) -> Result, Self::Rejection> { + match >::from_request_parts(parts, state).await { + Ok(identity) => Ok(Some(identity)), + Err(LoginError::Unauthorized) => Ok(None), + Err(other) => Err(other), + } + } +} + pub enum LoginError { Failure(E), Unauthorized, -- cgit v1.2.3