This commit is contained in:
Techiesplash 2024-08-02 23:44:57 -07:00
commit 3bf950d61c
5 changed files with 46 additions and 0 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/target

6
Cargo.toml Normal file
View file

@ -0,0 +1,6 @@
[package]
name = "accounter"
version = "0.1.0"
edition = "2021"
[dependencies]

3
README.md Normal file
View file

@ -0,0 +1,3 @@
# Accounter
Attempts to provide an agnostic, no-bullshit framework for accounts and authentication.

36
src/lib.rs Normal file
View file

@ -0,0 +1,36 @@
pub enum AuthError {
InvalidToken
}
pub struct Permission {
pub namespace: String,
pub name: String,
}
impl Permission {
fn new(namespace: String, name: String) -> Self {
Self {
namespace,
name
}
}
}
pub trait AuthUser {
type Id;
fn id(&self) -> Self::UserId;
fn delete(mut self) -> Self::Id;
}
pub trait AuthSession<AU: AuthUser> {
fn user(&self) -> AU;
fn has_permission(&self, permission: &Permission) -> bool;
fn grant_permission(&self, permission: &Permission, state: bool);
}
pub trait AuthProvider<AU: AuthUser, AS: AuthSession<AU>> {
type Token;
fn valid_token(&self, token: Self::Token) -> bool;
fn session_from_token(&self, token: Self::Token) -> Result<AS, AuthError>;
fn session_from_id(id: AU::Id) -> Result<AS, AuthError>;
}

0
tests/demo.rs Normal file
View file