@@ -12,6 +12,7 @@ use clap::ArgMatches;
1212use futures_util:: { pin_mut, StreamExt } ;
1313use tracing:: { debug, info, warn} ;
1414
15+ pub mod qrcode;
1516pub mod settings;
1617pub mod validate;
1718
@@ -174,28 +175,56 @@ pub async fn parse_matches(matches: ArgMatches) -> Result<()> {
174175 "Checking MFA status... (waited {}s/{})" ,
175176 wait_time, max_wait_time
176177 ) ;
177- let mfa_validated = web_client
178+ match web_client
178179 . check_mfa (
179180 mfa_type. clone ( ) ,
180181 otp_id. clone ( ) ,
181182 form_state. clone ( ) ,
182183 token. clone ( ) ,
183184 )
184- . await ?;
185-
186- if mfa_validated {
187- break ;
188- }
189-
190- if wait_time >= max_wait_time {
191- return Err ( anyhow:: anyhow!(
192- "MFA validation timed out after {} seconds" ,
193- max_wait_time
194- ) ) ;
185+ . await
186+ {
187+ Ok ( mfa_validated) => {
188+ if mfa_validated {
189+ break ;
190+ }
191+
192+ if wait_time >= max_wait_time {
193+ return Err ( anyhow:: anyhow!(
194+ "MFA validation timed out after {} seconds" ,
195+ max_wait_time
196+ ) ) ;
197+ }
198+
199+ wait_time += wait_interval;
200+ tokio:: time:: sleep ( std:: time:: Duration :: from_secs ( wait_interval) ) . await ;
201+ }
202+ Err ( e) => match e. downcast_ref ( ) {
203+ Some ( bourso_api:: client:: error:: ClientError :: QRCodeRequired ( code) ) => {
204+ match qrcode:: generate_qr_code ( code) {
205+ Ok ( qr) => {
206+ println ! ( ) ;
207+ println ! ( "{}" , qrcode:: render_to_terminal( & qr) ) ;
208+ println ! ( ) ;
209+ }
210+ Err ( e) => {
211+ debug ! ( "{:#?}" , e) ;
212+ return Err ( e) ;
213+ }
214+ }
215+ info ! (
216+ "Please scan the latest QR code in your BoursoBank app to validate the login request."
217+ ) ;
218+ wait_time += wait_interval;
219+ tokio:: time:: sleep ( std:: time:: Duration :: from_secs ( wait_interval) )
220+ . await ;
221+ }
222+ _ => {
223+ debug ! ( "{:#?}" , e) ;
224+ return Err ( e) ;
225+ }
226+ } ,
195227 }
196-
197- wait_time += wait_interval;
198- tokio:: time:: sleep ( std:: time:: Duration :: from_secs ( wait_interval) ) . await ;
199228 }
200229
201230 info ! ( "MFA successful ✅" ) ;
0 commit comments