Skip to main content

license_api/
auth.rs

1use reqwest::Client;
2use serde::{Deserialize, Serialize};
3use std::error::Error;
4
5#[derive(Serialize, Deserialize)]
6pub struct LoginRequest {
7    pub key: String,
8    pub hwid: String,
9}
10
11pub struct LicenseAPI {
12    url: String,
13    client: Client,
14}
15
16impl LicenseAPI {
17    pub fn new(url: impl Into<String>) -> Self {
18        LicenseAPI {
19            url: url.into(),
20            client: Client::new(),
21        }
22    }
23
24    pub async fn login(
25        &self,
26        creds: &LoginRequest,
27    ) -> Result<bool, Box<dyn Error + Send + Sync>> {
28        self
29            .client
30            .post(&format!("{}/license/auth", self.url.trim_end_matches('/')))
31            .json(creds)
32            .send()
33            .await?
34            .error_for_status()?;
35
36        Ok(true)
37    }
38}