bitwarden_auth/send_access/
access_token_response.rs1use std::fmt::Debug;
2
3use crate::send_access::api::{SendAccessTokenApiErrorResponse, SendAccessTokenApiSuccessResponse};
4
5#[derive(serde::Serialize, serde::Deserialize, Clone)]
7#[serde(rename_all = "camelCase", deny_unknown_fields)]
8#[bitwarden_ffi::wasm_record]
9#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
10#[derive(Debug)]
11pub struct SendAccessTokenResponse {
12 pub token: String,
14 pub expires_at: i64,
16}
17
18impl From<SendAccessTokenApiSuccessResponse> for SendAccessTokenResponse {
19 fn from(response: SendAccessTokenApiSuccessResponse) -> Self {
20 let expires_at =
24 chrono::Utc::now().timestamp_millis() + (response.expires_in * 1000) as i64;
25
26 SendAccessTokenResponse {
27 token: response.access_token,
28 expires_at,
29 }
30 }
31}
32
33#[bitwarden_error::bitwarden_error(full)]
36#[derive(Debug, thiserror::Error)]
37#[serde(tag = "kind", content = "data", rename_all = "lowercase")]
38pub enum SendAccessTokenError {
41 #[error("Unexpected Error response: {0:?}")]
42 Unexpected(UnexpectedIdentityError),
46
47 #[error("Expected error response")]
48 Expected(SendAccessTokenApiErrorResponse),
50}
51
52impl From<reqwest::Error> for SendAccessTokenError {
54 fn from(value: reqwest::Error) -> Self {
55 Self::Unexpected(UnexpectedIdentityError(format!("{value:?}")))
56 }
57}
58impl From<reqwest_middleware::Error> for SendAccessTokenError {
59 fn from(value: reqwest_middleware::Error) -> Self {
60 Self::Unexpected(UnexpectedIdentityError(format!("{value:?}")))
61 }
62}
63
64#[derive(Debug, PartialEq, serde::Serialize, serde::Deserialize)]
71#[serde(transparent)]
72#[bitwarden_ffi::wasm_record]
73pub struct UnexpectedIdentityError(pub String);
74
75#[cfg(feature = "uniffi")] uniffi::custom_newtype!(UnexpectedIdentityError, String);