pub struct AuthManager { /* private fields */ }Expand description
Server-side authentication manager.
Holds user credentials, in-flight SCRAM handshakes, and active bearer tokens.
Implementations§
Source§impl AuthManager
impl AuthManager
Sourcepub fn new(users: HashMap<String, UserRecord>, token_ttl: Duration) -> Self
pub fn new(users: HashMap<String, UserRecord>, token_ttl: Duration) -> Self
Create a new AuthManager with the given user records and token TTL.
Sourcepub fn with_token_ttl(self, duration: Duration) -> Self
pub fn with_token_ttl(self, duration: Duration) -> Self
Builder method to configure the token TTL.
Sourcepub fn from_toml_str(content: &str) -> Result<Self, String>
pub fn from_toml_str(content: &str) -> Result<Self, String>
Create an AuthManager from TOML content string.
Sourcepub fn is_enabled(&self) -> bool
pub fn is_enabled(&self) -> bool
Returns true if authentication is enabled (there are registered users).
Sourcepub fn handle_hello(
&self,
username: &str,
client_first_b64: Option<&str>,
) -> Result<String, String>
pub fn handle_hello( &self, username: &str, client_first_b64: Option<&str>, ) -> Result<String, String>
Handle a HELLO request: look up user, create SCRAM handshake.
client_first_b64 is the optional base64-encoded client-first-message
containing the client nonce. If absent, the server generates a nonce
(but the handshake will fail if the client expects its own nonce).
Returns the WWW-Authenticate header value for the 401 response.
Unknown users receive a fake but plausible challenge to prevent
username enumeration.
Sourcepub fn handle_scram(
&self,
handshake_token: &str,
data: &str,
) -> Result<(String, String), String>
pub fn handle_scram( &self, handshake_token: &str, data: &str, ) -> Result<(String, String), String>
Handle a SCRAM request: verify client proof, issue auth token.
Returns (auth_token, authentication_info_header_value).
Sourcepub fn validate_token(&self, token: &str) -> Option<AuthUser>
pub fn validate_token(&self, token: &str) -> Option<AuthUser>
Validate a bearer token and return the associated user.
Returns None if the token is unknown or has expired. Expired
tokens are automatically removed under a single write lock to
avoid TOCTOU races.
Sourcepub fn revoke_token(&self, token: &str) -> bool
pub fn revoke_token(&self, token: &str) -> bool
Remove a bearer token (logout / close).
Sourcepub fn check_permission(user: &AuthUser, required: &str) -> bool
pub fn check_permission(user: &AuthUser, required: &str) -> bool
Check whether a user has a required permission.