Skip to content

Commit 1344505

Browse files
committed
Switch to header auth
1 parent fe6d036 commit 1344505

2 files changed

Lines changed: 9 additions & 21 deletions

File tree

src/command/setup.rs

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{rpc, settings, verbosity, Result};
1+
use crate::{settings, verbosity, Result};
22
use clap::Args;
33
use colored_json::ToColoredJson;
44
use serde_json::json;
@@ -28,22 +28,7 @@ pub struct LoginArgs {
2828
}
2929

3030
pub fn login(args: &LoginArgs) -> Result<()> {
31-
let old_password = settings::get_str("password")?;
32-
settings::put_str("password", &args.password)?;
33-
match rpc::call("get_area", json!({ "id": "th" })) {
34-
Ok(res) => match res.error {
35-
Some(_) => {
36-
res.print()?;
37-
settings::put_str("password", &old_password)?;
38-
Err("Password is likely wrong")?
39-
}
40-
None => Ok(()),
41-
},
42-
Err(e) => {
43-
settings::put_str("password", &old_password)?;
44-
Err(e)?
45-
}
46-
}
31+
settings::put_str("password", &args.password)
4732
}
4833

4934
#[derive(Args)]

src/rpc.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,16 @@ impl RpcResponse {
2727
}
2828
}
2929

30-
pub fn call(method: &str, mut params: Value) -> Result<RpcResponse> {
30+
pub fn call(method: &str, params: Value) -> Result<RpcResponse> {
3131
if verbosity() > 0 {
3232
println!(
3333
"{}",
3434
serde_json::to_string(&params)?.to_colored_json_auto()?
3535
);
3636
}
3737
let params = params
38-
.as_object_mut()
38+
.as_object()
3939
.ok_or("params value is not a valid JSON object")?;
40-
params.insert("password".into(), settings::get_str("password")?.into());
4140
let args = json!(
4241
{"jsonrpc": "2.0", "method": method, "params": params, "id": 1}
4342
);
@@ -49,7 +48,11 @@ pub fn call(method: &str, mut params: Value) -> Result<RpcResponse> {
4948
println!("{}", serde_json::to_string(&args)?.to_colored_json_auto()?);
5049
}
5150
let response = ureq::post(api_url)
52-
//.header("Content-Type", "application/json")
51+
.header("Content-Type", "application/json")
52+
.header(
53+
"Authorization",
54+
format!("Bearer {}", settings::get_str("password")?),
55+
)
5356
.send_json(args)?
5457
.body_mut()
5558
.read_to_string()?;

0 commit comments

Comments
 (0)