Skip to content

Commit

Permalink
Pass token during MFA to skip user input prompt. (#23)
Browse files Browse the repository at this point in the history
Co-authored-by: Konstantin Munteanu <[email protected]>
  • Loading branch information
kublaios and mkon authored Aug 17, 2023
1 parent abf70ef commit c3c9af9
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions cli/src/commands/mfa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,25 @@ pub struct Command {
pub facility: Facility,
}

#[derive(Debug, Parser)]
pub struct Token {
/// Optional MFA code - If omitted you will be prompted instead
value: Option<String>,
}

#[derive(Debug, Subcommand)]
pub enum Facility {
/// For use with a token generator like Google Authenticator
Token,
Token(Token),
/// Enter the code which will be sent to your email address
Email,
/// Enter the code which will be sent to your Phone (SMS)
Mobile,
}

pub fn execute(cmd: &Command) {
match cmd.facility {
Facility::Token => token_flow(),
match &cmd.facility {
Facility::Token(token) => token_flow(token.value.clone()),
Facility::Email => request_flow("EMAIL"),
Facility::Mobile => request_flow("PHONE_TEXT"),
}
Expand All @@ -33,8 +39,15 @@ fn request_flow(facility: &str) {
super::wrap_in_spinner(|| mfa::submit(session, facility, &code), |r| r.message);
}

fn token_flow() {
let code = request_code();
fn token_flow(token: Option<String>) {
let code: String;

if let Some(t) = token {
code = t;
} else {
code = request_code();
}

super::wrap_in_spinner(
|| mfa::token(&super::get_session(), &code),
|r| if r { "Code valid".into() } else { "Code invalid".into() },
Expand Down

0 comments on commit c3c9af9

Please sign in to comment.