#[cfg(feature = "auth-by-http")]
mod auth_by_http;
#[cfg(feature = "auth-by-http")]
pub use auth_by_http::*;
use std::collections::HashMap;
#[async_trait::async_trait]
pub trait AuthPlugin: Send + Sync {
async fn login(&self, server_list: Vec<String>, auth_context: AuthContext);
fn get_login_identity(&self) -> LoginIdentityContext;
}
#[derive(Clone, Default)]
pub struct AuthContext {
pub(crate) params: HashMap<String, String>,
}
impl AuthContext {
pub fn add_param(mut self, key: impl Into<String>, val: impl Into<String>) -> Self {
self.params.insert(key.into(), val.into());
self
}
pub fn add_params(mut self, map: HashMap<String, String>) -> Self {
self.params.extend(map);
self
}
}
#[derive(Clone, Default)]
pub struct LoginIdentityContext {
pub(crate) contexts: HashMap<String, String>,
}
impl LoginIdentityContext {
pub fn add_context(mut self, key: impl Into<String>, val: impl Into<String>) -> Self {
self.contexts.insert(key.into(), val.into());
self
}
pub fn add_contexts(mut self, map: HashMap<String, String>) -> Self {
self.contexts.extend(map);
self
}
}
#[derive(Default)]
pub(crate) struct NoopAuthPlugin {
login_identity: LoginIdentityContext,
}
#[async_trait::async_trait]
impl AuthPlugin for NoopAuthPlugin {
#[allow(unused_variables)]
async fn login(&self, server_list: Vec<String>, auth_context: AuthContext) {
}
fn get_login_identity(&self) -> LoginIdentityContext {
self.login_identity.clone()
}
}