summaryrefslogtreecommitdiff
path: root/server/src/main.rs
diff options
context:
space:
mode:
authorKjetil Orbekk <kj@orbekk.com>2022-11-25 12:35:35 -0500
committerKjetil Orbekk <kj@orbekk.com>2022-11-25 12:35:35 -0500
commit9d191019757eae3bba45e8e1a021fefdc69a9fae (patch)
treedcb6d7d6e7a3aa726650e401b92e8484e049ff32 /server/src/main.rs
parentf4713b1ccf508c0ec1192ce8d800f21111e655e1 (diff)
Add fake authenticator
Diffstat (limited to 'server/src/main.rs')
-rw-r--r--server/src/main.rs23
1 files changed, 22 insertions, 1 deletions
diff --git a/server/src/main.rs b/server/src/main.rs
index 2363110..39425d6 100644
--- a/server/src/main.rs
+++ b/server/src/main.rs
@@ -19,6 +19,7 @@ mod auth;
mod error;
mod play;
mod server;
+mod fake_auth;
use crate::{
auth::{OauthAuthenticator, SessionId},
server::ServerContext,
@@ -28,6 +29,26 @@ use crate::{
play::{DbJournal, Journal},
};
use sqlx::{postgres::PgPoolOptions, PgPool};
+use auth::Authenticator;
+
+async fn create_default_authenticator(db_pool: &PgPool) -> Box<dyn Authenticator + Send + Sync> {
+ Box::new(OauthAuthenticator::from_env(db_pool.clone()).await)
+}
+
+#[cfg(debug_assertions)]
+async fn create_authenticator(db_pool: &PgPool) -> Box<dyn Authenticator + Send + Sync> {
+ const FAKE_AUTHENTICATOR: &str = "fake";
+ if std::env::var("AUTHENTICATOR").unwrap_or("".to_string()) == FAKE_AUTHENTICATOR {
+ Box::new(fake_auth::FakeAuthenticator {})
+ } else {
+ create_default_authenticator(db_pool).await
+ }
+}
+
+#[cfg(not(debug_assertions))]
+async fn create_authenticator(db_pool: &PgPool) -> Box<dyn Authenticator + Send + Sync> {
+ create_default_authenticator(db_pool)
+}
#[tokio::main]
async fn main() {
@@ -66,7 +87,7 @@ async fn main() {
let state = Arc::new(ServerContext {
app_url,
- authenticator: Box::new(OauthAuthenticator::from_env(db_pool.clone()).await),
+ authenticator: create_authenticator(&db_pool).await,
db: db_pool,
});