Initial
This commit is contained in:
commit
3bf950d61c
5 changed files with 46 additions and 0 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
/target
|
6
Cargo.toml
Normal file
6
Cargo.toml
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
[package]
|
||||||
|
name = "accounter"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
[dependencies]
|
3
README.md
Normal file
3
README.md
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
# Accounter
|
||||||
|
|
||||||
|
Attempts to provide an agnostic, no-bullshit framework for accounts and authentication.
|
36
src/lib.rs
Normal file
36
src/lib.rs
Normal 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
0
tests/demo.rs
Normal file
Reference in a new issue