@@ -9,19 +9,19 @@ mod state;
9
9
pub use client:: * ;
10
10
pub use error:: * ;
11
11
pub use ops:: * ;
12
+ pub use state:: LoginState ;
12
13
13
14
pub ( crate ) use config:: * ;
14
15
15
16
use crate :: context:: { Authentication , OAuth2Context , Reason } ;
16
- use gloo_storage:: { errors :: StorageError , SessionStorage , Storage } ;
17
+ use gloo_storage:: { SessionStorage , Storage } ;
17
18
use gloo_timers:: callback:: Timeout ;
18
19
use gloo_utils:: { history, window} ;
19
20
use js_sys:: Date ;
20
21
use log:: error;
21
22
use num_traits:: cast:: ToPrimitive ;
22
23
use reqwest:: Url ;
23
24
use state:: * ;
24
- use std:: fmt:: Display ;
25
25
use std:: { collections:: HashMap , fmt:: Debug , time:: Duration } ;
26
26
use tokio:: sync:: mpsc:: { channel, Receiver , Sender } ;
27
27
use wasm_bindgen:: JsValue ;
@@ -412,7 +412,7 @@ where
412
412
) )
413
413
}
414
414
Some ( state) => {
415
- let stored_state = Self :: get_from_store ( STORAGE_KEY_CSRF_TOKEN ) ?;
415
+ let stored_state = get_from_store ( STORAGE_KEY_CSRF_TOKEN ) ?;
416
416
417
417
if state != stored_state {
418
418
return Err ( OAuth2Error :: LoginResult ( "State mismatch" . to_string ( ) ) ) ;
@@ -427,7 +427,7 @@ where
427
427
428
428
log:: debug!( "Login state: {state:?}" ) ;
429
429
430
- let redirect_url = Self :: get_from_store ( STORAGE_KEY_REDIRECT_URL ) ?;
430
+ let redirect_url = get_from_store ( STORAGE_KEY_REDIRECT_URL ) ?;
431
431
log:: debug!( "Redirect URL: {redirect_url}" ) ;
432
432
let redirect_url = Url :: parse ( & redirect_url) . map_err ( |err| {
433
433
OAuth2Error :: LoginResult ( format ! ( "Failed to parse redirect URL: {err}" ) )
@@ -454,7 +454,7 @@ where
454
454
else {
455
455
return Ok ( ( ) ) ;
456
456
} ;
457
- let Some ( url) = Self :: get_from_store_optional ( STORAGE_KEY_POST_LOGIN_URL ) ? else {
457
+ let Some ( url) = get_from_store_optional ( STORAGE_KEY_POST_LOGIN_URL ) ? else {
458
458
return Ok ( ( ) ) ;
459
459
} ;
460
460
SessionStorage :: delete ( STORAGE_KEY_POST_LOGIN_URL ) ;
@@ -506,21 +506,6 @@ where
506
506
}
507
507
}
508
508
509
- fn get_from_store < K : AsRef < str > + Display > ( key : K ) -> Result < String , OAuth2Error > {
510
- Self :: get_from_store_optional ( & key) ?. ok_or_else ( || OAuth2Error :: storage_key_empty ( key) )
511
- }
512
-
513
- fn get_from_store_optional < K : AsRef < str > + Display > (
514
- key : K ,
515
- ) -> Result < Option < String > , OAuth2Error > {
516
- match SessionStorage :: get :: < String > ( key. as_ref ( ) ) {
517
- Err ( StorageError :: KeyNotFound ( _) ) => Ok ( None ) ,
518
- Err ( err) => Err ( OAuth2Error :: Storage ( err. to_string ( ) ) ) ,
519
- Ok ( value) if value. is_empty ( ) => Err ( OAuth2Error :: storage_key_empty ( key) ) ,
520
- Ok ( value) => Ok ( Some ( value) ) ,
521
- }
522
- }
523
-
524
509
/// Extract the state from the query.
525
510
fn find_query_state ( ) -> Option < State > {
526
511
if let Ok ( url) = Self :: current_url ( ) {
0 commit comments