@@ -170,11 +170,10 @@ impl StatelessClient {
170170 Ok ( Self { oidc, http, env } )
171171 }
172172
173- pub async fn login < F , Fut , C > ( & self , open_url : F ) -> Result < AuthState >
173+ pub async fn login < F , Fut > ( & self , open_url : F ) -> Result < AuthState >
174174 where
175175 F : FnOnce ( String , CancellationToken ) -> Fut ,
176- Fut : Future < Output = Option < C > > ,
177- C : FnOnce ( ) + Send + ' static ,
176+ Fut : Future < Output = ( ) > ,
178177 {
179178 let ( pkce_challenge, pkce_verifier) = PkceCodeChallenge :: new_random_sha256 ( ) ;
180179
@@ -199,19 +198,11 @@ impl StatelessClient {
199198 let cancel_token = CancellationToken :: new ( ) ;
200199 let cancel_token_for_opener = cancel_token. clone ( ) ;
201200
202- // Open the auth URL; opener may return a close handle to close the window when done.
203- let mut close_handle = open_url ( auth_url. to_string ( ) , cancel_token_for_opener) . await ;
201+ open_url ( auth_url. to_string ( ) , cancel_token_for_opener) . await ;
204202
205- let recv_result = redirect_server
203+ let authorization_code = redirect_server
206204 . recv_with_timeout ( LOGIN_TIMEOUT , Some ( & cancel_token) )
207- . await ;
208-
209- // Close the auth window if one was opened (e.g. in-app webview), on success or error.
210- if let Some ( close) = close_handle. take ( ) {
211- close ( ) ;
212- }
213-
214- let authorization_code = recv_result?;
205+ . await ?;
215206 debug ! ( "received redirect with authorization code" ) ;
216207
217208 // Exchange auth code for ID and access tokens.
@@ -572,9 +563,8 @@ impl AuthClient {
572563 /// Fetch fresh OIDC provider metadata (including JWKs) and swap in a new client.
573564 /// Call before login/refresh to avoid "No matching key found" when keys rotate.
574565 async fn ensure_fresh_client ( & self ) -> Result < Arc < StatelessClient > > {
575- let fresh = Arc :: new (
576- StatelessClient :: with_provider ( self . env , self . env . auth_provider ( ) ) . await ?,
577- ) ;
566+ let fresh =
567+ Arc :: new ( StatelessClient :: with_provider ( self . env , self . env . auth_provider ( ) ) . await ?) ;
578568 self . client . store ( fresh. clone ( ) ) ;
579569 Ok ( fresh)
580570 }
@@ -667,27 +657,18 @@ impl AuthClient {
667657 }
668658
669659 pub async fn login ( & self ) -> Result < ( ) > {
670- self . login_with_opener ( |url, _cancel_token| async move {
671- if let Err ( err) = open:: that ( & url) {
672- warn ! ( "Failed to auto-open url: {err}" ) ;
673- eprintln ! ( "Open this URL in a browser to complete the login:\n {url}" ) ;
674- }
675- None :: < Box < dyn FnOnce ( ) + Send > >
676- } )
677- . await
678- }
679-
680- pub async fn login_with_opener < F , Fut , C > ( & self , open_url : F ) -> Result < ( ) >
681- where
682- F : FnOnce ( String , CancellationToken ) -> Fut ,
683- Fut : Future < Output = Option < C > > ,
684- C : FnOnce ( ) + Send + ' static ,
685- {
686660 let auth = self . state . load ( ) ;
687661 let auth = match auth. get ( ) {
688662 Err ( _) => {
689663 let client = self . ensure_fresh_client ( ) . await ?;
690- client. login ( open_url) . await ?
664+ client
665+ . login ( |url, _cancel_token| async move {
666+ if let Err ( err) = open:: that ( & url) {
667+ warn ! ( "Failed to auto-open url: {err}" ) ;
668+ eprintln ! ( "Open this URL in a browser to complete the login:\n {url}" ) ;
669+ }
670+ } )
671+ . await ?
691672 }
692673 Ok ( auth) if auth. tokens . expires_in_less_than ( REFRESH_AUTH_WHEN ) => {
693674 let client = self . ensure_fresh_client ( ) . await ?;
@@ -700,9 +681,10 @@ impl AuthClient {
700681 . login ( |url, _cancel_token| async move {
701682 if let Err ( e) = open:: that ( & url) {
702683 warn ! ( "Failed to auto-open url: {e}" ) ;
703- eprintln ! ( "Open this URL in a browser to complete the login:\n {url}" ) ;
684+ eprintln ! (
685+ "Open this URL in a browser to complete the login:\n {url}"
686+ ) ;
704687 }
705- None :: < Box < dyn FnOnce ( ) + Send > >
706688 } )
707689 . await ?
708690 }
@@ -828,8 +810,7 @@ mod redirect_server {
828810 use tokio_util:: sync:: CancellationToken ;
829811 use tracing:: { Instrument , debug, instrument, warn} ;
830812
831- static LOGIN_SUCCESS_PNG : & [ u8 ] =
832- include_bytes ! ( "../../../ui/assets/images/login-success.png" ) ;
813+ static LOGIN_SUCCESS_PNG : & [ u8 ] = include_bytes ! ( "../../../ui/assets/images/login-success.png" ) ;
833814 static ALLIANCE_NO1_REGULAR_TTF : & [ u8 ] =
834815 include_bytes ! ( "../../../ui/assets/fonts/AllianceNo1-Regular.ttf" ) ;
835816 static FAVICON_LIGHT_32 : & [ u8 ] =
@@ -944,13 +925,15 @@ mod redirect_server {
944925 sender : mpsc:: Sender < n0_error:: Result < OauthRedirectData > > ,
945926 }
946927
947- async fn oauth_redirect ( state : State < AppState > , query : Query < OauthRedirectData > ) -> axum:: response:: Html < String > {
928+ async fn oauth_redirect (
929+ state : State < AppState > ,
930+ query : Query < OauthRedirectData > ,
931+ ) -> axum:: response:: Html < String > {
948932 let data = query. 0 ;
949933 state. sender . send ( Ok ( data) ) . await . ok ( ) ;
950934
951935 let hero_b64 = BASE64 . encode ( LOGIN_SUCCESS_PNG ) ;
952936 let font_b64 = BASE64 . encode ( ALLIANCE_NO1_REGULAR_TTF ) ;
953- let favicon_light_b64 = BASE64 . encode ( FAVICON_LIGHT_32 ) ;
954937 let favicon_dark_b64 = BASE64 . encode ( FAVICON_DARK_32 ) ;
955938 let html = OAUTH_REDIRECT_HTML
956939 . replace ( "{{HERO_B64}}" , & hero_b64)
0 commit comments