Skip to content

Commit

Permalink
Skip selection phase if only 1 MFA option
Browse files Browse the repository at this point in the history
  • Loading branch information
DannyDaoBoYang committed May 17, 2023
1 parent 467bfde commit 244c3e5
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/D2L.Bmx/Authenticate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,17 +126,23 @@ private static List<OktaSessionCache> ReadOktaSessionCacheFile() {
}

private static int PromptMfa( MfaOption[] mfaOptions ) {

Console.WriteLine( "MFA Required" );
for( int i = 0; i < mfaOptions.Length; i++ ) {
Console.WriteLine( $"[{i + 1}] {mfaOptions[i].Provider}: {mfaOptions[i].Name}" );
}
Console.Write( "Select an available MFA option: " );
if( !int.TryParse( Console.ReadLine(), out int index ) || index > mfaOptions.Length || index < 1 ) {
throw new BmxException( "Invalid account selection" );
if( mfaOptions.Length > 1 ) {
for( int i = 0; i < mfaOptions.Length; i++ ) {
Console.WriteLine( $"[{i + 1}] {mfaOptions[i].Provider}: {mfaOptions[i].Name}" );
}
Console.Write( "Select an available MFA option: " );
if( !int.TryParse( Console.ReadLine(), out int index ) || index > mfaOptions.Length || index < 1 ) {
throw new BmxException( "Invalid account selection" );
}
return index;
} else if( mfaOptions.Length == 0 ) {//idk, is mfaOptions' length gaurenteed to be >= 1?
throw new BmxException( "No MFA method have been set up for the current user." );
} else {
Console.WriteLine( $"MFA method: {mfaOptions[0].Provider}: {mfaOptions[0].Name}" );
return 1;
}

return index;
}

private static string PromptMfaInput( string mfaInputPrompt ) {
Expand Down

0 comments on commit 244c3e5

Please sign in to comment.