diff options
author | Cara Salter <cara@devcara.com> | 2022-06-28 07:07:34 -0400 |
---|---|---|
committer | Cara Salter <cara@devcara.com> | 2022-06-28 07:07:34 -0400 |
commit | 8de1eae2b49d763dcac55b8a2a84673475a35e63 (patch) | |
tree | 3b2d385b590c4211cf311042122563b89dcc6e51 /src/handlers | |
parent | f516a9616b7160be149ef4ba8726557e019bf621 (diff) | |
download | solard-8de1eae2b49d763dcac55b8a2a84673475a35e63.tar.gz solard-8de1eae2b49d763dcac55b8a2a84673475a35e63.zip |
auth: Scaffold auth/begin [WIP]
Diffstat (limited to 'src/handlers')
-rw-r--r-- | src/handlers/auth.rs | 34 | ||||
-rw-r--r-- | src/handlers/mod.rs | 1 |
2 files changed, 35 insertions, 0 deletions
diff --git a/src/handlers/auth.rs b/src/handlers/auth.rs new file mode 100644 index 0000000..a9ac394 --- /dev/null +++ b/src/handlers/auth.rs @@ -0,0 +1,34 @@ +use std::collections::HashMap; + +use axum::{extract::Query, Extension}; +use axum_macros::debug_handler; +use pasetors::{claims::Claims, keys::{AsymmetricKeyPair, Generate}, version4::V4}; +use uuid::Uuid; + +use crate::{errors::{NoneResult, ServiceError}, State}; + + +/** + * Takes in a request to create a new token with a secret key that gets printed + * to stdout and, if it matches, returns a valid PASETO token that can be used + * for future authentication + */ +#[debug_handler] +pub async fn begin(Query(params): Query<HashMap<String, String>>, Extension(state): Extension<State>) -> NoneResult { + if let Some(k) = params.get("key") { + if k == &state.gen_key { + let mut claims = Claims::new()?; + claims.non_expiring(); + claims.audience("solard")?; + claims.add_additional("uuid", Uuid::new_v4().to_string())?; + + let kp = AsymmetricKeyPair::<V4>::generate()?; + } else { + return Err(ServiceError::NotAuthorized); + } + } else { + return Err(ServiceError::Generic("No key supplied".to_string())); + } + + Ok(()) +} diff --git a/src/handlers/mod.rs b/src/handlers/mod.rs index 591f76e..8f8224e 100644 --- a/src/handlers/mod.rs +++ b/src/handlers/mod.rs @@ -1 +1,2 @@ pub mod planets; +pub mod auth; |