diff --git a/services/identity/Cargo.lock b/services/identity/Cargo.lock --- a/services/identity/Cargo.lock +++ b/services/identity/Cargo.lock @@ -694,6 +694,7 @@ "futures-core", "opaque-ke", "prost", + "rand", "rusoto_core", "rusoto_dynamodb", "sha2", diff --git a/services/identity/Cargo.toml b/services/identity/Cargo.toml --- a/services/identity/Cargo.toml +++ b/services/identity/Cargo.toml @@ -20,6 +20,7 @@ tracing = "0.1" tracing-subscriber = "0.3" chrono = "0.4.19" +rand = "0.8" [build-dependencies] tonic-build = "0.6" diff --git a/services/identity/src/token.rs b/services/identity/src/token.rs --- a/services/identity/src/token.rs +++ b/services/identity/src/token.rs @@ -1,4 +1,8 @@ use chrono::{DateTime, Utc}; +use rand::{ + distributions::{DistString, Standard}, + rngs::OsRng, +}; pub enum AuthType { Password, @@ -11,3 +15,15 @@ pub auth_type: Option, pub valid: Option, } + +impl Token { + pub fn new(auth_type: AuthType) -> Self { + let mut rng = OsRng; + Token { + token: Standard.sample_string(&mut rng, 512), + created: Some(Utc::now()), + auth_type: Some(auth_type), + valid: Some(true), + } + } +}