Skip to main content

alibi_core/store/contracts/
device.rs

1use super::*;
2/// Persistence for OAuth device authorization codes.
3#[async_trait]
4pub trait DeviceCodeStore: Send + Sync {
5    /// Persist a newly-issued device code.
6    async fn create_device_code(&self, input: CreateDeviceCode) -> AuthResult<DeviceCode>;
7    /// Fetch a device code by its opaque device-facing token.
8    async fn get_device_code_by_device_code(
9        &self,
10        device_code: &str,
11    ) -> AuthResult<Option<DeviceCode>>;
12    /// Fetch a device code by its user-facing verification code.
13    async fn get_device_code_by_user_code(&self, user_code: &str)
14    -> AuthResult<Option<DeviceCode>>;
15    /// Update mutable device-code state such as approval status or poll time.
16    async fn update_device_code(
17        &self,
18        id: &str,
19        update: UpdateDeviceCode,
20    ) -> AuthResult<DeviceCode>;
21    /// Update a device code only when it still has the expected status.
22    ///
23    /// Returns `true` when the compare-and-swap succeeds, or `false` when the
24    /// row was already moved to a different state.
25    async fn update_device_code_if_status(
26        &self,
27        id: &str,
28        current_status: &str,
29        update: UpdateDeviceCode,
30    ) -> AuthResult<bool>;
31    /// Bind a still-pending, still-unclaimed device code to a user.
32    ///
33    /// Returns `true` when this call performed the claim, and `false` when the
34    /// row was already claimed or no longer pending. The status and
35    /// unclaimed checks are part of the write so two concurrent verifiers
36    /// cannot both claim the same code.
37    async fn claim_device_code(&self, id: &str, user_id: &str) -> AuthResult<bool>;
38    /// Delete a device code record.
39    async fn delete_device_code(&self, id: &str) -> AuthResult<()>;
40    /// Delete a device code only when it still has the expected status.
41    ///
42    /// Returns `true` when a matching row was deleted and `false` otherwise.
43    async fn delete_device_code_if_status(&self, id: &str, status: &str) -> AuthResult<bool>;
44}