feat(auth): sessions and scoped API tokens
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
411a21ca6e
commit
c2d352ae30
7 files changed
+931
-13
No files matched your search
@@ -46,6 +46,8 @@ pub struct User {
|
||||
pub auth_epoch: u64,
|
||||
/// Set by `reset_admin`: no ordinary session until the password changes.
|
||||
pub must_change_password: bool,
|
||||
/// Unix seconds of the last `reauthenticate`; 0 if never.
|
||||
pub last_reauth: u64,
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for User {
|
||||
@@ -81,15 +83,28 @@ impl std::fmt::Debug for Session {
|
||||
}
|
||||
}
|
||||
|
||||
/// How much an API token may do. `Read` < `Admin`.
|
||||
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum Scope {
|
||||
#[default]
|
||||
Read,
|
||||
Admin,
|
||||
}
|
||||
|
||||
#[derive(Clone, Default, Serialize, Deserialize)]
|
||||
#[serde(default)]
|
||||
pub struct ApiToken {
|
||||
pub id: String,
|
||||
pub user_id: String,
|
||||
pub name: String,
|
||||
/// SHA-256 hex of the token; the token itself is never stored.
|
||||
pub token_hash: String,
|
||||
pub created_at: String,
|
||||
pub expires_at: Option<String>,
|
||||
pub scope: Scope,
|
||||
/// Unix seconds.
|
||||
pub created_at: u64,
|
||||
/// Unix seconds; every token expires.
|
||||
pub expires_at: u64,
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for ApiToken {
|
||||
|
||||
Reference in new issue
Block a user