From 99ff9cdc6890959cd4d2112c2e37b97ae83cb43c Mon Sep 17 00:00:00 2001 From: Vika Date: Sun, 9 Jul 2023 22:22:34 +0300 Subject: cargo update, part 2: Axum MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Axum got some breaking changes and gained some nice features — however, features come later, breaking changes come first. Perhaps it would be nice to actually construct a State with all of my stuff, and then make functions generic over that. Could reduce the amount of generic stuff I am producing... maybe. --- kittybox-rs/src/indieauth/mod.rs | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) (limited to 'kittybox-rs/src/indieauth') diff --git a/kittybox-rs/src/indieauth/mod.rs b/kittybox-rs/src/indieauth/mod.rs index a86100d..0ad2702 100644 --- a/kittybox-rs/src/indieauth/mod.rs +++ b/kittybox-rs/src/indieauth/mod.rs @@ -73,20 +73,20 @@ impl axum::response::IntoResponse for IndieAuthResourceError { } #[async_trait::async_trait] -impl axum::extract::FromRequest for User { +impl axum::extract::FromRequestParts for User { type Rejection = IndieAuthResourceError; - async fn from_request(req: &mut axum::extract::RequestParts) -> Result { + async fn from_request_parts(req: &mut axum::http::request::Parts, state: &S) -> Result { let TypedHeader(Authorization(token)) = - TypedHeader::>::from_request(req) + TypedHeader::>::from_request_parts(req, state) .await .map_err(|_| IndieAuthResourceError::Unauthorized)?; - let axum::Extension(auth) = axum::Extension::::from_request(req) + let axum::Extension(auth) = axum::Extension::::from_request_parts(req, state) .await .unwrap(); - let Host(host) = Host::from_request(req) + let Host(host) = Host::from_request_parts(req, state) .await .map_err(|_| IndieAuthResourceError::InvalidRequest)?; @@ -253,9 +253,9 @@ async fn verify_credential( #[tracing::instrument(skip(backend, confirmation))] async fn authorization_endpoint_confirm( Host(host): Host, - Json(confirmation): Json, Extension(backend): Extension, cookies: CookieJar, + Json(confirmation): Json, ) -> Response { tracing::debug!("Received authorization confirmation from user"); #[cfg(feature = "webauthn")] @@ -318,11 +318,12 @@ async fn authorization_endpoint_confirm( .into_response() } +#[tracing::instrument(skip(backend, db))] async fn authorization_endpoint_post( Host(host): Host, - Form(grant): Form, Extension(backend): Extension, - Extension(db): Extension + Extension(db): Extension, + Form(grant): Form, ) -> Response { match grant { GrantRequest::AuthorizationCode { @@ -373,9 +374,9 @@ async fn authorization_endpoint_post( error_uri: None }.into_response() } - let profile = if dbg!(request.scope.as_ref() + let profile = if request.scope.as_ref() .map(|s| s.has(&Scope::Profile)) - .unwrap_or_default()) + .unwrap_or_default() { match get_profile( db, @@ -384,7 +385,10 @@ async fn authorization_endpoint_post( .map(|s| s.has(&Scope::Email)) .unwrap_or_default() ).await { - Ok(profile) => dbg!(profile), + Ok(profile) => { + tracing::debug!("Retrieved profile: {:?}", profile); + profile + }, Err(err) => { tracing::error!("Error retrieving profile from database: {}", err); @@ -408,9 +412,9 @@ async fn authorization_endpoint_post( #[tracing::instrument(skip(backend, db))] async fn token_endpoint_post( Host(host): Host, - Form(grant): Form, Extension(backend): Extension, - Extension(db): Extension + Extension(db): Extension, + Form(grant): Form, ) -> Response { #[inline] fn prepare_access_token(me: url::Url, client_id: url::Url, scope: Scopes) -> TokenData { @@ -655,11 +659,12 @@ async fn token_endpoint_post( } } +#[tracing::instrument(skip(backend, token_request))] async fn introspection_endpoint_post( Host(host): Host, - Form(token_request): Form, TypedHeader(Authorization(auth_token)): TypedHeader>, - Extension(backend): Extension + Extension(backend): Extension, + Form(token_request): Form, ) -> Response { use serde_json::json; @@ -693,8 +698,8 @@ async fn introspection_endpoint_post( async fn revocation_endpoint_post( Host(host): Host, + Extension(backend): Extension, Form(revocation): Form, - Extension(backend): Extension ) -> impl IntoResponse { let me: url::Url = format!("https://{}/", host).parse().unwrap(); -- cgit 1.4.1