Skip to content

Commit

Permalink
validate account credentials
Browse files Browse the repository at this point in the history
  • Loading branch information
ranfdev committed Nov 15, 2023
1 parent 084e450 commit aae34e9
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions ntfy-daemon/src/system_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,12 +485,25 @@ impl system_notifier::Server for SystemNotifier {
mut results: system_notifier::AddAccountResults,
) -> capnp::capability::Promise<(), capnp::Error> {
let keyring = self.env.keyring.clone();
let http = self.env.http.clone();
Promise::from_future(async move {
let account = params.get()?.get_account()?;
let username = account.get_username()?.to_str()?;
let server = account.get_server()?.to_str()?;
let password = params.get()?.get_password()?.to_str()?;

info!("validating account");
let url = models::Subscription::build_url(server, "stats", 0)
.map_err(|e| capnp::Error::failed(e.to_string()))?;

http.get(url)
.basic_auth(username, Some(password))
.send()
.await
.map_err(|e| capnp::Error::failed(e.to_string()))?
.error_for_status()
.map_err(|e| capnp::Error::failed(e.to_string()))?;

let attrs = HashMap::from([
("type", "password"),
("username", username),
Expand Down

0 comments on commit aae34e9

Please sign in to comment.