mangadex_api_schema_rust/v5/
oauth.rs

1use mangadex_api_types::ApiClientProfile;
2use serde::Deserialize;
3
4use crate::FromResponse;
5
6use super::AuthTokens;
7
8#[derive(Debug, Deserialize, Clone)]
9#[cfg_attr(feature = "non_exhaustive", non_exhaustive)]
10#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
11#[cfg_attr(feature = "specta", derive(specta::Type))]
12pub struct OAuthTokenResponse {
13    pub access_token: String,
14    pub expires_in: u32,
15    pub refresh_expires_in: u32,
16    pub refresh_token: String,
17    pub token_type: String,
18    #[serde(default)]
19    #[serde(alias = "not-before-policy")]
20    pub not_before_policy: u32,
21    pub session_state: uuid::Uuid,
22    pub scope: String,
23    pub client_type: ApiClientProfile,
24}
25
26impl From<OAuthTokenResponse> for AuthTokens {
27    fn from(value: OAuthTokenResponse) -> Self {
28        Self {
29            session: value.access_token.to_owned(),
30            refresh: value.refresh_token.clone(),
31        }
32    }
33}
34
35impl FromResponse for OAuthTokenResponse {
36    type Response = Self;
37
38    fn from_response(res: Self::Response) -> Self {
39        res
40    }
41}
42
43#[derive(Debug, Deserialize, Clone)]
44#[serde(rename_all = "camelCase")]
45#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
46#[cfg_attr(feature = "specta", derive(specta::Type))]
47pub struct ClientInfo {
48    pub client_id: String,
49    pub client_secret: String,
50}