Add implicit authentication flow (#255)
All checks were successful
continuous-integration/drone/push Build is passing

Reviewed-on: #255
Co-authored-by: Pierre HUBERT <pierre.git@communiquons.org>
Co-committed-by: Pierre HUBERT <pierre.git@communiquons.org>
This commit is contained in:
2024-03-28 21:13:25 +00:00
committed by Pierre Hubert
parent 7060ce3fe4
commit 0a5649fcb9
6 changed files with 163 additions and 64 deletions

View File

@@ -4,6 +4,12 @@ use crate::utils::string_utils::apply_env_vars;
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize, Eq, PartialEq)]
pub struct ClientID(pub String);
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum AuthenticationFlow {
AuthorizationCode,
Implicit,
}
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
pub struct Client {
/// The ID of the client
@@ -16,7 +22,8 @@ pub struct Client {
pub description: String,
/// The secret used by the client to retrieve authenticated users information
pub secret: String,
/// This value is absent if implicit authentication flow is used
pub secret: Option<String>,
/// The URI where the users should be redirected once authenticated
pub redirect_uri: String,
@@ -42,6 +49,16 @@ impl PartialEq for Client {
impl Eq for Client {}
impl Client {
/// Get the client authentication flow
pub fn auth_flow(&self) -> AuthenticationFlow {
match self.secret {
None => AuthenticationFlow::Implicit,
Some(_) => AuthenticationFlow::AuthorizationCode,
}
}
}
pub type ClientManager = EntityManager<Client>;
impl EntityManager<Client> {
@@ -66,7 +83,7 @@ impl EntityManager<Client> {
c.id = ClientID(apply_env_vars(&c.id.0));
c.name = apply_env_vars(&c.name);
c.description = apply_env_vars(&c.description);
c.secret = apply_env_vars(&c.secret);
c.secret = c.secret.as_deref().map(apply_env_vars);
c.redirect_uri = apply_env_vars(&c.redirect_uri);
}
}