Private
Public Access
1
0

daemon: setting foundation for client creation

This commit is contained in:
2025-04-25 20:02:18 -07:00
parent fe32efef2c
commit 82192ffbe5
10 changed files with 210 additions and 27 deletions

View File

@@ -8,7 +8,7 @@ edition = "2021"
[dependencies]
async-trait = "0.1.80"
base64 = "0.22.1"
chrono = "0.4.38"
chrono = { version = "0.4.38", features = ["serde"] }
ctor = "0.2.8"
env_logger = "0.11.5"
hyper = { version = "0.14", features = ["full"] }

View File

@@ -26,3 +26,27 @@ pub trait APIInterface {
async fn authenticate(&mut self, credentials: Credentials) -> Result<JwtToken, Self::Error>;
}
pub trait TokenManagement {
fn get_token(&mut self) -> Option<JwtToken>;
fn set_token(&mut self, token: JwtToken);
}
pub struct InMemoryTokenManagement {
token: Option<JwtToken>,
}
impl InMemoryTokenManagement {
pub fn new() -> Self {
Self { token: None }
}
}
impl TokenManagement for InMemoryTokenManagement {
fn get_token(&mut self) -> Option<JwtToken> {
self.token.clone()
}
fn set_token(&mut self, token: JwtToken) {
self.token = Some(token);
}
}

View File

@@ -7,23 +7,23 @@ use base64::{
use chrono::{DateTime, Utc};
use hyper::http::HeaderValue;
use serde::Deserialize;
use serde::{Deserialize, Serialize};
#[derive(Deserialize, Debug, Clone)]
#[derive(Deserialize, Serialize, Debug, Clone)]
#[allow(dead_code)]
struct JwtHeader {
alg: String,
typ: String,
}
#[derive(Deserialize, Debug, Clone)]
#[derive(Deserialize, Serialize, Debug, Clone)]
#[allow(dead_code)]
enum ExpValue {
Integer(i64),
String(String),
}
#[derive(Deserialize, Debug, Clone)]
#[derive(Deserialize, Serialize, Debug, Clone)]
#[allow(dead_code)]
struct JwtPayload {
exp: serde_json::Value,
@@ -31,7 +31,7 @@ struct JwtPayload {
user: Option<String>,
}
#[derive(Debug, Clone)]
#[derive(Deserialize, Serialize, Debug, Clone)]
#[allow(dead_code)]
pub struct JwtToken {
header: JwtHeader,