From 3bf950d61c236e78d0b0d7862e8403a1013bbef6 Mon Sep 17 00:00:00 2001 From: Techiesplash <94077364+Techiesplash@users.noreply.github.com> Date: Fri, 2 Aug 2024 23:44:57 -0700 Subject: [PATCH] Initial --- .gitignore | 1 + Cargo.toml | 6 ++++++ README.md | 3 +++ src/lib.rs | 36 ++++++++++++++++++++++++++++++++++++ tests/demo.rs | 0 5 files changed, 46 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.toml create mode 100644 README.md create mode 100644 src/lib.rs create mode 100644 tests/demo.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..4962f1d --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "accounter" +version = "0.1.0" +edition = "2021" + +[dependencies] diff --git a/README.md b/README.md new file mode 100644 index 0000000..b45d138 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# Accounter + +Attempts to provide an agnostic, no-bullshit framework for accounts and authentication. \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..dd59ab0 --- /dev/null +++ b/src/lib.rs @@ -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 { + fn user(&self) -> AU; + fn has_permission(&self, permission: &Permission) -> bool; + fn grant_permission(&self, permission: &Permission, state: bool); +} + +pub trait AuthProvider> { + type Token; + fn valid_token(&self, token: Self::Token) -> bool; + fn session_from_token(&self, token: Self::Token) -> Result; + fn session_from_id(id: AU::Id) -> Result; +} \ No newline at end of file diff --git a/tests/demo.rs b/tests/demo.rs new file mode 100644 index 0000000..e69de29