pub struct TotpService<S> { /* private fields */ }Expand description
TOTP service — handles setup, verification, and backup codes.
Secrets are stored as CredentialKind::Passkey entries (reusing the
credential row with kind "passkey" to avoid schema changes).
The secret is stored as a base32-encoded string in credential_hash.
Backup codes are SHA-256 hashed and stored in metadata as a JSON array.
Implementations§
Source§impl<S> TotpService<S>
impl<S> TotpService<S>
pub fn new(storage: S, app_name: impl Into<Arc<str>>) -> Self
Sourcepub async fn begin_setup(&self, user_id: Uuid) -> Result<TotpSetup>
pub async fn begin_setup(&self, user_id: Uuid) -> Result<TotpSetup>
Generate a new TOTP secret and backup codes for a user.
Call confirm_setup with the first code before persisting.
Sourcepub async fn confirm_setup(
&self,
user_id: Uuid,
setup: &TotpSetup,
code: &str,
) -> Result<()>
pub async fn confirm_setup( &self, user_id: Uuid, setup: &TotpSetup, code: &str, ) -> Result<()>
Confirm the user can produce a valid code, then persist the secret.
Sourcepub async fn verify(&self, req: TotpVerifyRequest) -> Result<()>
pub async fn verify(&self, req: TotpVerifyRequest) -> Result<()>
Verify a TOTP code (or a backup code) during sign-in.
Sourcepub async fn is_enabled(&self, user_id: Uuid) -> Result<bool>
pub async fn is_enabled(&self, user_id: Uuid) -> Result<bool>
Returns true if the user has TOTP enabled.
Auto Trait Implementations§
impl<S> Freeze for TotpService<S>where
S: Freeze,
impl<S> RefUnwindSafe for TotpService<S>where
S: RefUnwindSafe,
impl<S> Send for TotpService<S>where
S: Send,
impl<S> Sync for TotpService<S>where
S: Sync,
impl<S> Unpin for TotpService<S>where
S: Unpin,
impl<S> UnsafeUnpin for TotpService<S>where
S: UnsafeUnpin,
impl<S> UnwindSafe for TotpService<S>where
S: UnwindSafe,
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
Mutably borrows from an owned value. Read more