Skip to content

Commit

Permalink
scaffolded auth backend type
Browse files Browse the repository at this point in the history
  • Loading branch information
johnbchron committed Jan 31, 2024
1 parent 3da7ccd commit 7abb5af
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 1 deletion.
4 changes: 4 additions & 0 deletions engine/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ members = ["crates/*"]
tokio = { version = "1.35.1", features = ["full"] }
color-eyre = "0.6.2"
axum = "0.7.4"
thiserror = "1.0.56"
tracing = "0.1.40"
tracing-subscriber = "0.3.18"
serde = { version = "1.0.196", features = ["derive"] }
Expand Down
5 changes: 5 additions & 0 deletions engine/crates/auth/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,9 @@ edition = "2021"
[dependencies]
axum-login = "0.13.1"
serde.workspace = true
color-eyre.workspace = true
thiserror.workspace = true
surrealdb.workspace = true

clients = { path = "../clients" }
async-trait = "0.1.77"
45 changes: 44 additions & 1 deletion engine/crates/auth/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use axum_login::AuthUser;
use axum_login::{AuthUser, AuthnBackend, UserId};
use serde::{Deserialize, Serialize};
use surrealdb::sql::Thing;

Expand All @@ -25,3 +25,46 @@ impl AuthUser for AuthenticatedUser {
fn id(&self) -> Self::Id { self.id.clone() }
fn session_auth_hash(&self) -> &[u8] { self.password.as_bytes() }
}

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Credentials {
pub username: String,
pub password: String,
pub next: Option<String>,
}

#[derive(Clone)]
pub struct Backend {
surreal_client: clients::surreal::SurrealRootClient,
}

impl Backend {
pub async fn new() -> color_eyre::Result<Self> {
Ok(Self {
surreal_client: clients::surreal::SurrealRootClient::new().await?,
})
}
}

#[async_trait::async_trait]
impl AuthnBackend for Backend {
type User = AuthenticatedUser;
type Credentials = Credentials;
type Error = std::convert::Infallible;

async fn authenticate(
&self,
credentials: Self::Credentials,
) -> Result<Option<Self::User>, Self::Error> {
let surreal_client = &self.surreal_client;

Ok(None)
}

async fn get_user(
&self,
user_id: &UserId<Self>,
) -> Result<Option<Self::User>, Self::Error> {
Ok(None)
}
}
1 change: 1 addition & 0 deletions engine/crates/clients/src/surreal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use surrealdb::{
};

/// A root-level client for the SurrealDB database.
#[derive(Clone, Debug)]
pub struct SurrealRootClient {
client: surrealdb::Surreal<Client>,
}
Expand Down

0 comments on commit 7abb5af

Please sign in to comment.