about summary refs log tree commit diff
path: root/src/indieauth
diff options
context:
space:
mode:
Diffstat (limited to 'src/indieauth')
-rw-r--r--src/indieauth/mod.rs19
-rw-r--r--src/indieauth/webauthn.rs4
2 files changed, 18 insertions, 5 deletions
diff --git a/src/indieauth/mod.rs b/src/indieauth/mod.rs
index 0ac3dfd..ab38715 100644
--- a/src/indieauth/mod.rs
+++ b/src/indieauth/mod.rs
@@ -3,10 +3,10 @@ use microformats::types::Class;
 use tracing::error;
 use serde::Deserialize;
 use axum::{
-    extract::{Form, FromRef, Host, Json, Query, State}, http::StatusCode, response::{Html, IntoResponse, Response}
+    extract::{Form, FromRef, Json, Query, State}, http::StatusCode, response::{Html, IntoResponse, Response}
 };
 #[cfg_attr(not(feature = "webauthn"), allow(unused_imports))]
-use axum_extra::extract::cookie::{CookieJar, Cookie};
+use axum_extra::extract::{Host, cookie::{CookieJar, Cookie}};
 use axum_extra::{headers::{authorization::Bearer, Authorization, ContentType, HeaderMapExt}, TypedHeader};
 use crate::database::Storage;
 use kittybox_indieauth::{
@@ -65,7 +65,20 @@ impl axum::response::IntoResponse for IndieAuthResourceError {
     }
 }
 
-#[async_trait::async_trait]
+impl <A: AuthBackend + FromRef<St>, St: Clone + Send + Sync + 'static> axum::extract::OptionalFromRequestParts<St> for User<A> {
+    type Rejection = <Self as axum::extract::FromRequestParts<St>>::Rejection;
+
+    async fn from_request_parts(req: &mut axum::http::request::Parts, state: &St) -> Result<Option<Self>, Self::Rejection> {
+        let res = <Self as axum::extract::FromRequestParts<St>>::from_request_parts(req, state).await;
+
+        match res {
+            Ok(user) => Ok(Some(user)),
+            Err(IndieAuthResourceError::Unauthorized) => Ok(None),
+            Err(err) => Err(err),
+        }
+    }
+}
+
 impl <A: AuthBackend + FromRef<St>, St: Clone + Send + Sync + 'static> axum::extract::FromRequestParts<St> for User<A> {
     type Rejection = IndieAuthResourceError;
 
diff --git a/src/indieauth/webauthn.rs b/src/indieauth/webauthn.rs
index b7d8c71..0757e72 100644
--- a/src/indieauth/webauthn.rs
+++ b/src/indieauth/webauthn.rs
@@ -1,9 +1,9 @@
 use axum::{
-    extract::{Json, Host},
+    extract::Json,
     response::{IntoResponse, Response},
     http::StatusCode, Extension
 };
-use axum_extra::extract::cookie::{CookieJar, Cookie};
+use axum_extra::extract::{Host, cookie::{CookieJar, Cookie}};
 use axum_extra::{TypedHeader, headers::{authorization::Bearer, Authorization}};
 
 use super::backend::AuthBackend;