pub struct Accounts { /* private fields */ }Expand description
Independently versioned account store; an empty store is never published.
Implementations§
Source§impl Accounts
impl Accounts
Sourcepub fn api_keys(&self, username: &str) -> Result<Vec<&ApiKey>, String>
pub fn api_keys(&self, username: &str) -> Result<Vec<&ApiKey>, String>
List one account’s keys in creation order, without secrets or verifiers. Disabled accounts may still be inspected by the local administrator.
Sourcepub fn create_api_key(
&mut self,
username: &str,
label: &str,
now: u64,
) -> Result<(ApiKey, String), String>
pub fn create_api_key( &mut self, username: &str, label: &str, now: u64, ) -> Result<(ApiKey, String), String>
Issue an OS-random id.secret credential and retain only its salted verifier.
Both components contain 256 random bits encoded as lowercase hexadecimal.
The returned token can be shown once, after the caller successfully saves
the store under its writer lock; it cannot be recovered by later reads.
Password work must run on a bounded blocking worker for HTTP callers.
Sourcepub fn revoke_api_key(
&mut self,
username: &str,
key_id: &str,
) -> Result<(), String>
pub fn revoke_api_key( &mut self, username: &str, key_id: &str, ) -> Result<(), String>
Revoke exactly one named account’s key, leaving other keys and sessions valid.
Sourcepub fn authenticate_api_key(&self, token: &str) -> Option<(&Account, &ApiKey)>
pub fn authenticate_api_key(&self, token: &str) -> Option<(&Account, &ApiKey)>
Verify an exact id.secret credential and return its enabled account and key.
Well-formed unknown keys perform the same bounded Argon2 work as known
keys. HTTP callers must schedule verification on a bounded worker and
apply admission/rate limits; these persistent tokens are not sessions.
Sourcepub fn api_key_account(
&self,
key_id: &str,
owner: &str,
epoch: &str,
revision: u64,
) -> Option<&Account>
pub fn api_key_account( &self, key_id: &str, owner: &str, epoch: &str, revision: u64, ) -> Option<&Account>
Recheck a previously authenticated key after reloading the current store. This checks presence, owner, enabled state, epoch and generation without password work. The caller must already have verified the complete token; possessing a public key ID or account metadata is never authentication.
Source§impl Accounts
impl Accounts
Sourcepub fn bootstrap(
username: &str,
password: &str,
now: u64,
) -> Result<Accounts, String>
pub fn bootstrap( username: &str, password: &str, now: u64, ) -> Result<Accounts, String>
Create the first administrator, retaining the existing local owner.
Sourcepub fn find(&self, username: &str) -> Option<&Account>
pub fn find(&self, username: &str) -> Option<&Account>
Find a canonical login name, accepting an uppercase spelling.
Sourcepub fn authenticate(&self, username: &str, password: &str) -> Option<&Account>
pub fn authenticate(&self, username: &str, password: &str) -> Option<&Account>
Authenticate without distinguishing missing, disabled or wrong-password accounts. Password work must be scheduled on a bounded blocking worker by HTTP callers.
Sourcepub fn session_account(
&self,
owner: &str,
epoch: &str,
revision: u64,
) -> Option<&Account>
pub fn session_account( &self, owner: &str, epoch: &str, revision: u64, ) -> Option<&Account>
Validate the owner and generation captured by a session after a reload.
Sourcepub fn create(
&mut self,
username: &str,
password: &str,
role: Role,
now: u64,
) -> Result<(), String>
pub fn create( &mut self, username: &str, password: &str, role: Role, now: u64, ) -> Result<(), String>
Add an enabled account with a generated, immutable personal owner.
Sourcepub fn set_role(
&mut self,
username: &str,
role: Role,
now: u64,
) -> Result<(), String>
pub fn set_role( &mut self, username: &str, role: Role, now: u64, ) -> Result<(), String>
Change privileges while retaining at least one enabled administrator.
Sourcepub fn set_enabled(
&mut self,
username: &str,
enabled: bool,
now: u64,
) -> Result<(), String>
pub fn set_enabled( &mut self, username: &str, enabled: bool, now: u64, ) -> Result<(), String>
Disable or enable access, preserving every personal record.
Sourcepub fn rename(
&mut self,
username: &str,
replacement: &str,
now: u64,
) -> Result<(), String>
pub fn rename( &mut self, username: &str, replacement: &str, now: u64, ) -> Result<(), String>
Rename a login without moving personal data.
Sourcepub fn set_password(
&mut self,
username: &str,
password: &str,
now: u64,
) -> Result<(), String>
pub fn set_password( &mut self, username: &str, password: &str, now: u64, ) -> Result<(), String>
Replace a salted password verifier and invalidate this account’s sessions and API keys.
Sourcepub fn revoke(&mut self, username: &str, now: u64) -> Result<(), String>
pub fn revoke(&mut self, username: &str, now: u64) -> Result<(), String>
Revoke one account’s sessions and API keys without changing its password or opinions.
Sourcepub fn revoke_all(&mut self) -> Result<(), String>
pub fn revoke_all(&mut self) -> Result<(), String>
Invalidate all sessions and API keys, including credentials from before a backup restore.