@@ -179,7 +179,12 @@ func (ac *Client) handleCheckWebAuthn(ctx context.Context, doc *goquery.Document
179179 return ctx , req , err
180180}
181181
182+ // Improved OTP handling in handleOTP function
182183func (ac * Client ) handleOTP (ctx context.Context , doc * goquery.Document , requestURL * url.URL ) (context.Context , * http.Request , error ) {
184+ loginDetails , ok := ctx .Value (ctxKey ("login" )).(* creds.LoginDetails )
185+ if ! ok {
186+ return ctx , nil , fmt .Errorf ("no context value for 'login'" )
187+ }
183188 form , err := page .NewFormFromDocument (doc , "#otp-form" )
184189 if err != nil {
185190 return ctx , nil , errors .Wrap (err , "error extracting OTP form" )
@@ -191,9 +196,16 @@ func (ac *Client) handleOTP(ctx context.Context, doc *goquery.Document, requestU
191196 break
192197 }
193198 }
194-
195- token := prompter .StringRequired ("Enter passcode" )
196- form .Values .Set ("otp" , token )
199+ // Improved MFA token handling with retry capability
200+ var mfaToken string
201+ if loginDetails .MFAToken != "" {
202+ mfaToken = loginDetails .MFAToken
203+ // Clear the token to allow for retry on failure
204+ loginDetails .MFAToken = ""
205+ } else {
206+ mfaToken = prompter .StringRequired ("Enter passcode" )
207+ }
208+ form .Values .Set ("otp" , mfaToken )
197209 req , err := form .BuildRequest ()
198210 return ctx , req , err
199211}
0 commit comments