diff options
| author | Owen Jacobson <owen@grimoire.ca> | 2025-02-19 21:22:03 -0500 |
|---|---|---|
| committer | Owen Jacobson <owen@grimoire.ca> | 2025-02-19 21:22:03 -0500 |
| commit | 74f80d5c11d0a212a545f053bfd4ca160bcedcd8 (patch) | |
| tree | 764b93d3b5723ee5ecebabba7fff89ea7abf0876 /src/token | |
| parent | 8a2b499fc7e00e841c56d23ac41f4d587b728a50 (diff) | |
Upgrade Axum to 0.8.1.
Diffstat (limited to 'src/token')
| -rw-r--r-- | src/token/extract/cookie.rs | 1 | ||||
| -rw-r--r-- | src/token/extract/identity.rs | 18 |
2 files changed, 16 insertions, 3 deletions
diff --git a/src/token/extract/cookie.rs b/src/token/extract/cookie.rs index af5787d..df03aea 100644 --- a/src/token/extract/cookie.rs +++ b/src/token/extract/cookie.rs @@ -71,7 +71,6 @@ impl Identity { } } -#[async_trait::async_trait] impl<S> FromRequestParts<S> for Identity where S: Send + Sync, 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, |
