Skip to main content

SqliteStore

Struct SqliteStore 

Source
pub struct SqliteStore { /* private fields */ }

Implementations§

Source§

impl SqliteStore

Source

pub async fn open(path: PathBuf) -> Result<Self, AuthError>

Source

pub async fn open_with_key( path: PathBuf, enc_key: Option<TokenEncryptionKey>, ) -> Result<Self, AuthError>

Source

pub async fn pragma(&self, name: &str) -> Result<String, AuthError>

Source

pub async fn register_client( &self, client: RegisteredClient, ) -> Result<(), AuthError>

Source

pub async fn find_client( &self, client_id: &str, ) -> Result<Option<RegisteredClient>, AuthError>

Source

pub async fn insert_authorization_request( &self, request: AuthorizationRequestRow, ) -> Result<(), AuthError>

Source

pub async fn take_authorization_request( &self, state: &str, ) -> Result<AuthorizationRequestRow, AuthError>

Source

pub async fn insert_auth_code( &self, code: AuthorizationCodeRow, ) -> Result<(), AuthError>

Source

pub async fn redeem_auth_code( &self, code: &str, ) -> Result<AuthorizationCodeRow, AuthError>

Source

pub async fn upsert_refresh_token( &self, token: RefreshTokenRow, ) -> Result<(), AuthError>

Insert a new refresh token row, storing a SHA-256 hash of the raw token as the primary key. The plaintext token is never persisted; only the caller-returned value contains it. If an encryption key is configured, provider_refresh_token is encrypted at rest before storage.

Use Self::rotate_refresh_token instead of calling this twice when replacing an existing token — that method performs the swap atomically.

Source

pub async fn rotate_refresh_token( &self, old_token: &str, new_token: RefreshTokenRow, ) -> Result<Option<RefreshTokenRow>, AuthError>

Atomically replace an existing refresh token with a new one in a single SQLite transaction. The old token is deleted and the new token is inserted; if the old token is not found or has expired the operation fails without inserting the new row (replay-safe).

Both the DELETE and the INSERT are wrapped in an explicit BEGIN / COMMIT so a crash between the two statements cannot leave the database without a valid refresh token.

Returns the newly issued RefreshTokenRow (with refresh_token set to the new plaintext value) on success.

Source

pub async fn find_refresh_token( &self, refresh_token: &str, ) -> Result<Option<RefreshTokenRow>, AuthError>

Source

pub async fn has_any_refresh_token(&self) -> Result<bool, AuthError>

Whether any unexpired refresh token has ever been issued, for any client. This is a single-tenant, admin-only gateway, so “someone already completed the Google consent screen once” is a reasonable proxy for “we don’t need to force full re-consent again” without having to know which subject is about to authenticate.

No longer called internally — authorize() now uses the provider-scoped Self::has_any_refresh_token_for_provider instead (this unscoped version incorrectly treats “some OTHER provider already has a refresh token on file” as a reason to skip forced consent on a user’s very first login with a different provider). Retained as general-purpose public API for other consumers of this shared crate, not because removing the internal call site was an accident — do not assume this is dead code to delete.

Source

pub async fn has_any_refresh_token_for_provider( &self, provider: &str, ) -> Result<bool, AuthError>

Same as Self::has_any_refresh_token, scoped to one provider.

authorize() (Task 11) uses this instead of the unscoped version to decide whether to force the upstream consent screen — the unscoped version incorrectly treats “Google already has a refresh token on file” as a reason to skip forced consent on a user’s very first Authelia or GitHub login, silently degrading that new provider’s first session to no local refresh token.

Source

pub async fn upsert_browser_session( &self, session: BrowserSessionRow, ) -> Result<(), AuthError>

Source

pub async fn find_browser_session( &self, session_id: &str, ) -> Result<Option<BrowserSessionRow>, AuthError>

Source

pub async fn revoke_browser_session( &self, session_id: &str, ) -> Result<(), AuthError>

Source

pub async fn execute_test_statement(&self, sql: &str) -> Result<(), AuthError>

Run an arbitrary SQL batch against the store — test fixtures only.

Gated behind cfg(any(test, debug_assertions)) (deliberately not a Cargo feature, mirroring upstream::cache’s test seam) so an arbitrary-SQL execution method can never ship in --all-features --release artifacts.

Source

pub async fn insert_browser_login_state( &self, login: BrowserLoginStateRow, ) -> Result<(), AuthError>

Source

pub async fn count_pending_oauth_states(&self) -> Result<usize, AuthError>

Source

pub async fn take_browser_login_state( &self, state: &str, ) -> Result<Option<BrowserLoginStateRow>, AuthError>

Source

pub async fn insert_native_authorization_result( &self, result: NativeAuthorizationResultRow, ) -> Result<(), AuthError>

Store a native-flow authorization code keyed by state, for the polling desktop client to retrieve via take_native_authorization_result.

Last-write-wins on a state collision (e.g. a client retrying /authorize with the same state after a timeout): each row is single-use (deleted on first successful poll), so overwriting with the newest code is correct — silently dropping the newest code instead (DO NOTHING) would leave the polling client hung until the row’s TTL expires, with no error surfaced anywhere.

Source

pub async fn take_native_authorization_result( &self, state: &str, ) -> Result<Option<NativeAuthorizationResultRow>, AuthError>

One-shot read-and-delete of a pending native-flow authorization code.

Source

pub async fn cleanup_expired(&self) -> Result<u64, AuthError>

Delete expired rows from all short-lived tables. Also drops upstream OAuth credential rows whose access token has expired AND have no refresh token available for re-use (SEC-9). Returns the total number of deleted rows.

Source

pub async fn upsert_upstream_oauth_credentials( &self, row: UpstreamOauthCredentialRow, ) -> Result<(), AuthError>

Source

pub async fn find_upstream_oauth_credentials( &self, upstream_name: &str, subject: &str, ) -> Result<Option<UpstreamOauthCredentialRow>, AuthError>

Source

pub async fn delete_upstream_oauth_credentials( &self, upstream_name: &str, subject: &str, ) -> Result<(), AuthError>

Source

pub async fn save_upstream_oauth_state( &self, row: UpstreamOauthStateRow, ) -> Result<(), AuthError>

Source

pub async fn find_upstream_oauth_state_subject( &self, upstream_name: &str, csrf_token: &str, now: i64, ) -> Result<Option<String>, AuthError>

Source

pub async fn find_upstream_oauth_state_owner( &self, csrf_token: &str, now: i64, ) -> Result<Option<(String, String)>, AuthError>

Look up (upstream_name, subject) by csrf_token alone.

Used by the OAuth callback handler to recover the upstream identity from the state parameter without requiring the caller to know it upfront.

Source

pub async fn delete_upstream_oauth_state_by_csrf( &self, csrf_token: &str, now: i64, ) -> Result<(), AuthError>

Delete a pending OAuth state token by CSRF token to foreclose replay attacks after exchange failure.

Source

pub async fn set_upstream_oauth_state_client_id( &self, upstream_name: &str, csrf_token: &str, client_id: &str, ) -> Result<(), AuthError>

Bind a dynamic OAuth client_id to a pending CSRF state row.

Called by begin_authorization after generating the authorization URL so that complete_authorization_callback can later look up which client_id was used for this specific flow (lab-77y5.15).

Source

pub async fn get_upstream_oauth_state_client_id( &self, upstream_name: &str, csrf_token: &str, now: i64, ) -> Result<Option<String>, AuthError>

Retrieve the dynamic_client_id bound to a pending CSRF state row.

Returns None when no row matches or the row has expired. Used by complete_authorization_callback to recover the exact client_id that was used when the authorization URL was generated (lab-77y5.15).

Source

pub async fn take_upstream_oauth_state( &self, upstream_name: &str, subject: &str, csrf_token: &str, now: i64, ) -> Result<Option<UpstreamOauthStateRow>, AuthError>

Atomic take-once via DELETE ... RETURNING.

Source

pub async fn save_dynamic_client_registration( &self, upstream_name: &str, subject: &str, client_id: &str, ) -> Result<(), AuthError>

Source

pub async fn find_dynamic_client_registration( &self, upstream_name: &str, subject: &str, ) -> Result<Option<String>, AuthError>

Source

pub async fn delete_dynamic_client_registration( &self, upstream_name: &str, subject: &str, ) -> Result<(), AuthError>

Source

pub async fn add_allowed_user( &self, email: &str, added_by: &str, created_at: i64, ) -> Result<(), AuthError>

Add an email address to the allowlist.

email is normalised to lowercase before storage. Returns AuthError::Validation if the email is already present.

Source

pub async fn remove_allowed_user(&self, email: &str) -> Result<(), AuthError>

Remove an email address from the allowlist.

Idempotent: returns Ok(()) even if the email was not present.

Source

pub async fn list_allowed_users(&self) -> Result<Vec<AllowedUserRow>, AuthError>

Return all allowlist rows ordered by created_at ASC.

Trait Implementations§

Source§

impl Clone for SqliteStore

Source§

fn clone(&self) -> SqliteStore

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SqliteStore

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FromRef<T> for T
where T: Clone,

§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,