File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 8484 Ok ( attempts. pop ( ) )
8585 }
8686
87+ pub async fn complete_login_attempt (
88+ & self ,
89+ attempt : LoginAttempt ,
90+ ) -> Result < LoginAttempt , StoreError > {
91+ let mut attempt: NewLoginAttempt = attempt. into ( ) ;
92+ attempt. attempt_state = LoginAttemptState :: Complete ;
93+ LoginAttemptStore :: upsert ( & * self . storage , attempt) . await
94+ }
95+
8796 pub async fn fail_login_attempt (
8897 & self ,
8998 attempt : LoginAttempt ,
Original file line number Diff line number Diff line change @@ -505,7 +505,7 @@ where
505505 tracing:: debug!( "Authorized code exchange" ) ;
506506
507507 // Lookup the request assigned to this code
508- let attempt = ctx
508+ let mut attempt = ctx
509509 . login
510510 . get_login_attempt_for_code ( & body. code )
511511 . await
@@ -533,6 +533,24 @@ where
533533
534534 tracing:: debug!( "Retrieved user information from remote provider" ) ;
535535
536+ // During fetch_user_info we revoke any downstream codes if possible, therefore At this point we
537+ // consider the login attempt to be consumed and can no longer be used. We state transition to
538+ // complete, even though we may fail further along in the handler. If a failure occurs then the
539+ // user will need to re-authenticate.
540+ attempt = ctx
541+ . login
542+ . complete_login_attempt ( attempt)
543+ . await
544+ . map_err ( |err| {
545+ tracing:: error!( ?err, "Failed to complete login attempt" ) ;
546+ OAuthError {
547+ error : OAuthErrorCode :: ServerError ,
548+ error_description : Some ( "An unexpected error occurred" . to_string ( ) ) ,
549+ error_uri : None ,
550+ state : None ,
551+ }
552+ } ) ?;
553+
536554 // Register this user as an API user if needed
537555 let ( api_user_info, api_user_provider) = ctx
538556 . register_api_user ( & ctx. builtin_registration_user ( ) , info)
You can’t perform that action at this time.
0 commit comments