pub struct AuthService { /* private fields */ }Expand description
The auth service. Cheap to clone: it holds a database handle and config.
Implementations§
Source§impl AuthService
impl AuthService
pub fn new(db: Db, config: AuthConfig) -> Self
Sourcepub async fn authenticate(
&self,
username: &str,
password: &str,
ctx: &RequestContext,
) -> Result<IssuedSession, AuthError>
pub async fn authenticate( &self, username: &str, password: &str, ctx: &RequestContext, ) -> Result<IssuedSession, AuthError>
Verifies a username and password, and on success issues a session.
Failures are throttled per username and every outcome is logged. The error deliberately does not reveal whether the username exists.
Sourcepub async fn resolve_session(
&self,
token: &str,
) -> Result<ResolvedSession, AuthError>
pub async fn resolve_session( &self, token: &str, ) -> Result<ResolvedSession, AuthError>
Resolves a raw session token to an identity and its stored data blob,
refreshing last-seen. Expired sessions, and sessions whose user was
disabled or removed, resolve to AuthError::SessionInvalid. The blob
is read in the same query as the session, adding no round-trip.
Sourcepub async fn verify_session(
&self,
token: &str,
) -> Result<AuthenticatedUser, AuthError>
pub async fn verify_session( &self, token: &str, ) -> Result<AuthenticatedUser, AuthError>
Resolves a raw session token to an identity. A thin wrapper over
AuthService::resolve_session for callers that need only the identity.
Sourcepub async fn set_session_data(
&self,
token: &str,
data: &str,
) -> Result<(), AuthError>
pub async fn set_session_data( &self, token: &str, data: &str, ) -> Result<(), AuthError>
Overwrites the opaque per-session data blob (the surface’s serialised state, e.g. CSRF token + flash). The surface writes only when its blob changed, so an unchanged request adds no write.
Sourcepub async fn logout(&self, token: &str) -> Result<(), AuthError>
pub async fn logout(&self, token: &str) -> Result<(), AuthError>
Invalidates a session. Unknown tokens are a no-op.
Sourcepub async fn set_user_timezone(
&self,
user_id: i64,
timezone: Option<&str>,
) -> Result<(), AuthError>
pub async fn set_user_timezone( &self, user_id: i64, timezone: Option<&str>, ) -> Result<(), AuthError>
Persists an operator’s own display timezone. Some(name) sets an IANA
timezone; None clears it so the operator falls back to the deployment
default. Validating that name is a real timezone is the caller’s job.
Sourcepub async fn set_user_locale(
&self,
user_id: i64,
locale: Option<&str>,
) -> Result<(), AuthError>
pub async fn set_user_locale( &self, user_id: i64, locale: Option<&str>, ) -> Result<(), AuthError>
Persists an operator’s own UI locale. Some(tag) sets a base language tag;
None clears it so the operator falls back to the deployment default.
Validating that tag is a supported locale is the caller’s job.
Sourcepub async fn user_permission_overrides(
&self,
user_id: i64,
) -> Result<HashMap<String, i64>, AuthError>
pub async fn user_permission_overrides( &self, user_id: i64, ) -> Result<HashMap<String, i64>, AuthError>
Loads a user’s per-permission overrides (code to 1 allow or -1 deny).
Sourcepub async fn set_user_permissions(
&self,
user_id: i64,
overrides: &HashMap<String, i64>,
) -> Result<(), AuthError>
pub async fn set_user_permissions( &self, user_id: i64, overrides: &HashMap<String, i64>, ) -> Result<(), AuthError>
Replaces a user’s per-permission overrides. Callers pass only 1 and -1
entries; an inherited permission is represented by its absence.
Sourcepub async fn record_audit(&self, entry: AuditEntry<'_>) -> Result<(), AuthError>
pub async fn record_audit(&self, entry: AuditEntry<'_>) -> Result<(), AuthError>
Appends an entry to the append-only audit log. Mutating admin paths call this after a successful change, so actions that affect privileges or data are recorded. Self-service preference changes are not audited.
Sourcepub async fn recent_audit(
&self,
limit: u64,
) -> Result<Vec<AuditRecord>, AuthError>
pub async fn recent_audit( &self, limit: u64, ) -> Result<Vec<AuditRecord>, AuthError>
The most recent audit entries, newest first, for the admin audit view.
Sourcepub async fn has_any_operator(&self) -> Result<bool, AuthError>
pub async fn has_any_operator(&self) -> Result<bool, AuthError>
Whether any backend operator exists yet. A fresh install with none is routed to first-run setup instead of login.
Sourcepub async fn create_superuser(
&self,
new: NewOperator<'_>,
) -> Result<i64, AuthError>
pub async fn create_superuser( &self, new: NewOperator<'_>, ) -> Result<i64, AuthError>
Creates a superuser operator: hashes the password, inserts the user, and records their timezone preference. The single account-creation path, shared by the CLI and the first-run setup screen.
Trait Implementations§
Source§impl Clone for AuthService
impl Clone for AuthService
Source§fn clone(&self) -> AuthService
fn clone(&self) -> AuthService
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for AuthService
impl !UnwindSafe for AuthService
impl Freeze for AuthService
impl Send for AuthService
impl Sync for AuthService
impl Unpin for AuthService
impl UnsafeUnpin for AuthService
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more