From dedc9243f532dd771d16c1b8596921af4a6707de Mon Sep 17 00:00:00 2001 From: Suya1671 Date: Sun, 20 Jul 2025 00:59:22 +0200 Subject: [PATCH] fix: fix oauth route --- src/oauth.rs | 59 ++++++++++++++++++++++++++-------------------------- 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/src/oauth.rs b/src/oauth.rs index 2846665..1b4a932 100755 --- a/src/oauth.rs +++ b/src/oauth.rs @@ -1,6 +1,6 @@ use axum::{ extract::{FromRequestParts, Query, State}, - http::{StatusCode, request::Parts}, + http::{self, StatusCode, request::Parts}, }; use oauth2::{ AuthUrl, AuthorizationCode, ClientId, ClientSecret, EndpointNotSet, EndpointSet, RedirectUrl, @@ -62,18 +62,17 @@ pub struct OauthCode { pub state: String, } -pub struct Url(url::Url); +#[derive(Debug)] +pub struct Uri(http::Uri); -impl FromRequestParts for Url +impl FromRequestParts for Uri where S: Send + Sync, { type Rejection = (StatusCode, &'static str); async fn from_request_parts(parts: &mut Parts, _state: &S) -> Result { - let url = url::Url::parse(&parts.uri.to_string()) - .map_err(|_| (StatusCode::BAD_REQUEST, "Invalid URL"))?; - Ok(Self(url)) + Ok(Self(parts.uri.clone())) } } @@ -81,7 +80,7 @@ where pub async fn oauth_handler( Query(code): Query, State(state): State, - Url(url): Url, + Uri(_uri): Uri, ) -> String { let db = &state.db; @@ -145,34 +144,36 @@ pub async fn oauth_handler( let response = format!("System for user {} authenticated!", record.owner_id.0); - if let Err(e) = slack_client - .post_webhook_message( - &url, - &SlackApiPostWebhookMessageRequest::new( - SlackMessageContent::new() - .with_text(response.clone()), - ), - ) - .await { - error!("Error sending Slack message: {:#?}", e); - } + // seemingly fails behind nest + // if let Err(e) = slack_client + // .post_webhook_message( + // &url, + // &SlackApiPostWebhookMessageRequest::new( + // SlackMessageContent::new() + // .with_text(response.clone()), + // ), + // ) + // .await { + // error!("Error sending Slack message: {:#?}", e); + // } response } Err(e) => { let response = format!("Error creating system: {e:#?}"); - if let Err(e) = slack_client - .post_webhook_message( - &url, - &SlackApiPostWebhookMessageRequest::new( - SlackMessageContent::new() - .with_text(response.clone()), - ), - ) - .await { - error!("Error sending Slack message: {:#?}", e); - } + // seemingly fails behind nest + // if let Err(e) = slack_client + // .post_webhook_message( + // &url, + // &SlackApiPostWebhookMessageRequest::new( + // SlackMessageContent::new() + // .with_text(response.clone()), + // ), + // ) + // .await { + // error!("Error sending Slack message: {:#?}", e); + // } error!("{response}"); response