@@ -48,39 +48,6 @@ use crate::{
4848 } ,
4949} ;
5050
51- // Async HTTP client for OAuth2 token requests using reqwest
52- async fn http_client (
53- request : oauth2:: HttpRequest ,
54- ) -> Result < oauth2:: HttpResponse , Box < dyn std:: error:: Error + Send + Sync > > {
55- use http:: header:: { HeaderName , HeaderValue } ;
56-
57- let client = reqwest:: Client :: new ( ) ;
58- let method = request. method ( ) . clone ( ) ;
59- let url = request. uri ( ) . to_string ( ) ;
60- let headers = request. headers ( ) . clone ( ) ;
61- let body = request. body ( ) . clone ( ) ;
62-
63- let mut request_builder = client. request ( method, & url) . body ( body) ;
64-
65- for ( name, value) in headers. iter ( ) {
66- request_builder = request_builder. header ( name. as_str ( ) , value. as_bytes ( ) ) ;
67- }
68-
69- let response = request_builder. send ( ) . await ?;
70-
71- let status_code = response. status ( ) ;
72- let headers = response. headers ( ) . clone ( ) ;
73- let body = response. bytes ( ) . await ?. to_vec ( ) ;
74-
75- let mut http_response = http:: Response :: builder ( ) . status ( status_code) ;
76-
77- for ( name, value) in headers. iter ( ) {
78- http_response = http_response. header ( name, value) ;
79- }
80-
81- Ok ( http_response. body ( body) ?)
82- }
83-
8451pub async fn register (
8552 State ( state) : State < AppState > ,
8653 Json ( payload) : Json < RegisterRequest > ,
@@ -441,6 +408,7 @@ pub async fn google_callback(
441408 } ) ?;
442409
443410 // Exchange the code for an access token
411+ let http_client = reqwest:: Client :: new ( ) ;
444412 let token_result = client
445413 . exchange_code ( AuthorizationCode :: new ( query. code ) )
446414 . request_async ( & http_client)
@@ -713,6 +681,7 @@ pub async fn github_callback(
713681 } ) ?;
714682
715683 // Exchange the code for an access token
684+ let http_client = reqwest:: Client :: new ( ) ;
716685 let token_result = client
717686 . exchange_code ( AuthorizationCode :: new ( query. code ) )
718687 . request_async ( & http_client)
@@ -1047,6 +1016,7 @@ pub async fn apple_callback(
10471016 } ) ?;
10481017
10491018 // Exchange the code for an access token
1019+ let http_client = reqwest:: Client :: new ( ) ;
10501020 let _token_result = client
10511021 . exchange_code ( AuthorizationCode :: new ( query. code . clone ( ) ) )
10521022 . request_async ( & http_client)
@@ -1341,6 +1311,7 @@ pub async fn facebook_callback(
13411311 } ) ?;
13421312
13431313 // Exchange the code for an access token
1314+ let http_client = reqwest:: Client :: new ( ) ;
13441315 let token_result = client
13451316 . exchange_code ( AuthorizationCode :: new ( query. code ) )
13461317 . request_async ( & http_client)
@@ -1654,6 +1625,7 @@ pub async fn linkedin_callback(
16541625 } ) ?;
16551626
16561627 // Exchange the code for an access token
1628+ let http_client = reqwest:: Client :: new ( ) ;
16571629 let token_result = client
16581630 . exchange_code ( AuthorizationCode :: new ( query. code . clone ( ) ) )
16591631 . request_async ( & http_client)
0 commit comments