pub struct AuthManager { /* private fields */ }Expand description
Authentication manager
Implementations§
Source§impl AuthManager
impl AuthManager
Sourcepub fn with_auth_repository(self, repo: Arc<EventSourcedAuthRepository>) -> Self
pub fn with_auth_repository(self, repo: Arc<EventSourcedAuthRepository>) -> Self
Attach an event-sourced auth repository for durable API key storage.
Loads all previously persisted keys into the in-memory cache.
Subsequent create_api_key and revoke_api_key calls will also
write events to the system WAL.
Sourcepub fn register_user(
&self,
username: String,
email: String,
password: &str,
role: Role,
tenant_id: String,
) -> Result<User>
pub fn register_user( &self, username: String, email: String, password: &str, role: Role, tenant_id: String, ) -> Result<User>
Register a new user
Sourcepub fn authenticate(&self, username: &str, password: &str) -> Result<String>
pub fn authenticate(&self, username: &str, password: &str) -> Result<String>
Authenticate user with username and password
Sourcepub fn validate_token(&self, token: &str) -> Result<Claims>
pub fn validate_token(&self, token: &str) -> Result<Claims>
Validate JWT token
Sourcepub fn create_api_key(
&self,
name: String,
tenant_id: String,
role: Role,
expires_at: Option<DateTime<Utc>>,
) -> (ApiKey, String)
pub fn create_api_key( &self, name: String, tenant_id: String, role: Role, expires_at: Option<DateTime<Utc>>, ) -> (ApiKey, String)
Create API key
When an auth repository is attached, the key is persisted to the system WAL and survives restarts.
Sourcepub fn validate_api_key(&self, key: &str) -> Result<Claims>
pub fn validate_api_key(&self, key: &str) -> Result<Claims>
Validate API key
Sourcepub fn list_users(&self) -> Vec<User>
pub fn list_users(&self) -> Vec<User>
List all users (admin only)
Sourcepub fn delete_user(&self, user_id: &Uuid) -> Result<()>
pub fn delete_user(&self, user_id: &Uuid) -> Result<()>
Delete user
Sourcepub fn revoke_api_key(&self, key_id: &Uuid) -> Result<()>
pub fn revoke_api_key(&self, key_id: &Uuid) -> Result<()>
Revoke API key
When an auth repository is attached, the revocation is persisted to the system WAL and survives restarts.
Sourcepub fn list_api_keys(&self, tenant_id: &str) -> Vec<ApiKey>
pub fn list_api_keys(&self, tenant_id: &str) -> Vec<ApiKey>
List API keys for a tenant
Sourcepub fn register_bootstrap_api_key(&self, key: &str, tenant_id: &str) -> ApiKey
pub fn register_bootstrap_api_key(&self, key: &str, tenant_id: &str) -> ApiKey
Register a bootstrap API key with a specific key value.
This is used on startup to create a pre-configured API key from
the ALLSOURCE_BOOTSTRAP_API_KEY environment variable.
If an auth repository is attached, the key is persisted to the system WAL. On subsequent restarts, the key is loaded from storage automatically — the bootstrap only creates the key if it doesn’t already exist (idempotent).