rustical_store/auth/
mod.rs1pub mod middleware;
2mod principal;
3use crate::error::Error;
4use async_trait::async_trait;
5
6mod principal_type;
7pub use principal_type::*;
8
9pub use principal::{AppToken, Principal};
10
11#[async_trait]
12pub trait AuthenticationProvider: Send + Sync + 'static {
13 async fn get_principals(&self) -> Result<Vec<Principal>, crate::Error>;
14 async fn get_principal(&self, id: &str) -> Result<Option<Principal>, crate::Error>;
15 async fn remove_principal(&self, id: &str) -> Result<(), crate::Error>;
16 async fn insert_principal(&self, user: Principal, overwrite: bool) -> Result<(), crate::Error>;
17 async fn validate_password(
18 &self,
19 user_id: &str,
20 password: &str,
21 ) -> Result<Option<Principal>, Error>;
22 async fn validate_app_token(
23 &self,
24 user_id: &str,
25 token: &str,
26 ) -> Result<Option<Principal>, Error>;
27 async fn add_app_token(
29 &self,
30 user_id: &str,
31 name: String,
32 token: String,
33 ) -> Result<String, Error>;
34 async fn remove_app_token(&self, user_id: &str, token_id: &str) -> Result<(), Error>;
35 async fn get_app_tokens(&self, principal: &str) -> Result<Vec<AppToken>, Error>;
36
37 async fn add_membership(&self, principal: &str, member_of: &str) -> Result<(), Error>;
38 async fn remove_membership(&self, principal: &str, member_of: &str) -> Result<(), Error>;
39 async fn list_members(&self, principal: &str) -> Result<Vec<String>, Error>;
40}
41
42pub use middleware::AuthenticationMiddleware;