diff options
| author | Kit La Touche <kit@transneptune.net> | 2025-02-21 22:18:56 -0500 |
|---|---|---|
| committer | Kit La Touche <kit@transneptune.net> | 2025-02-21 22:53:49 -0500 |
| commit | 9d1dbac74866a6175c65a25bbd8a3ccbe8cf87e4 (patch) | |
| tree | f15b3f0695b948e335774aa4d92a5b064a1c0f10 /src/token/extract/identity.rs | |
| parent | 743b59b69857da81b214970ec9252bc918ad243d (diff) | |
| parent | 36cadfe00cacc6a6523f9862d3f7a08a9d0ce611 (diff) | |
Merge branch 'main' into prop/preserve-state
Diffstat (limited to 'src/token/extract/identity.rs')
| -rw-r--r-- | src/token/extract/identity.rs | 18 |
1 files changed, 16 insertions, 2 deletions
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<App> for Identity { type Rejection = LoginError<Internal>; @@ -39,6 +38,21 @@ impl FromRequestParts<App> for Identity { } } +impl OptionalFromRequestParts<App> for Identity { + type Rejection = LoginError<Internal>; + + async fn from_request_parts( + parts: &mut Parts, + state: &App, + ) -> Result<Option<Self>, Self::Rejection> { + match <Self as FromRequestParts<App>>::from_request_parts(parts, state).await { + Ok(identity) => Ok(Some(identity)), + Err(LoginError::Unauthorized) => Ok(None), + Err(other) => Err(other), + } + } +} + pub enum LoginError<E> { Failure(E), Unauthorized, |
