alibi_core/store/contracts/
device.rs1use crate::{AuthError, AuthResult, CreateDeviceCode, DeviceCode, UpdateDeviceCode};
2use async_trait::async_trait;
3#[async_trait]
5pub trait DeviceCodeStore: Send + Sync {
6 async fn create_device_code(&self, input: CreateDeviceCode) -> AuthResult<DeviceCode>;
8 async fn create_device_code_with_fields(
10 &self,
11 input: CreateDeviceCode,
12 fields: serde_json::Map<String, serde_json::Value>,
13 ) -> AuthResult<DeviceCode> {
14 if fields.is_empty() {
15 self.create_device_code(input).await
16 } else {
17 Err(AuthError::not_implemented(
18 "Application device-grant fields are unsupported by this store",
19 ))
20 }
21 }
22 async fn device_code_fields(
24 &self,
25 _id: &str,
26 ) -> AuthResult<serde_json::Map<String, serde_json::Value>> {
27 Ok(serde_json::Map::new())
28 }
29 async fn consume_device_code(
31 &self,
32 _id: &str,
33 _status: &str,
34 _ownership: &serde_json::Map<String, serde_json::Value>,
35 ) -> AuthResult<Option<DeviceCode>> {
36 Err(AuthError::not_implemented(
37 "Atomic application device-grant redemption is unsupported by this store",
38 ))
39 }
40 async fn get_device_code_by_device_code(
42 &self,
43 device_code: &str,
44 ) -> AuthResult<Option<DeviceCode>>;
45 async fn get_device_code_by_user_code(&self, user_code: &str)
47 -> AuthResult<Option<DeviceCode>>;
48 async fn update_device_code(
50 &self,
51 id: &str,
52 update: UpdateDeviceCode,
53 ) -> AuthResult<DeviceCode>;
54 async fn update_device_code_if_status(
59 &self,
60 id: &str,
61 current_status: &str,
62 update: UpdateDeviceCode,
63 ) -> AuthResult<bool>;
64 async fn claim_device_code(&self, id: &str, user_id: &str) -> AuthResult<bool>;
71 async fn delete_device_code(&self, id: &str) -> AuthResult<()>;
73 async fn delete_device_code_if_status(&self, id: &str, status: &str) -> AuthResult<bool>;
77}