Skip to content

Commit 35381cf

Browse files
committed
base64 option for login command
1 parent 3d53041 commit 35381cf

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

tmc-langs-cli/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ anyhow = "1"
2121
quit = "1"
2222
dirs = "3"
2323
tempfile = "3"
24+
base64 = "0.12"
2425

2526
[dev-dependencies]
2627
tempfile = "3"

tmc-langs-cli/src/app.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,10 @@ pub fn create_app() -> App<'static, 'static> {
174174
.help("The OAUTH2 access token that should be used for authentication")
175175
.long("set-access-token")
176176
.takes_value(true)
177-
.required_unless("email")))
177+
.required_unless("email"))
178+
.arg(Arg::with_name("base64")
179+
.help("Write password as base64 encoded string.")
180+
.long("base64")))
178181

179182
.subcommand(SubCommand::with_name("logout")
180183
.about("Logout and remove OAuth2 token from config."))

tmc-langs-cli/src/main.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ mod output;
66
use output::{Output, OutputResult, Status};
77

88
use anyhow::{Context, Result};
9-
use clap::{Error, ErrorKind};
109
use serde::Serialize;
1110
use std::collections::HashMap;
1211
use std::env;
@@ -286,6 +285,7 @@ fn run() -> Result<()> {
286285
if let Some(matches) = matches.subcommand_matches("login") {
287286
let email = matches.value_of("email");
288287
let set_access_token = matches.value_of("set-access-token");
288+
let base64 = matches.is_present("base64");
289289

290290
// get token from argument or server
291291
let token = if let Some(token) = set_access_token {
@@ -299,7 +299,14 @@ fn run() -> Result<()> {
299299
} else if let Some(email) = email {
300300
// TODO: "Please enter password" and quiet param
301301
let password = rpassword::read_password().context("Failed to read password")?;
302-
core.authenticate(client_name, email.to_string(), password)
302+
let decoded = if base64 {
303+
let bytes = base64::decode(password).context("Password was invalid base64")?;
304+
String::from_utf8(bytes)
305+
.context("Base64 password decoded into invalid UTF-8")?
306+
} else {
307+
password
308+
};
309+
core.authenticate(client_name, email.to_string(), decoded)
303310
.context("Failed to authenticate with TMC")?
304311
} else {
305312
unreachable!("validation error");

0 commit comments

Comments
 (0)