mangadex_api_schema_rust/v5/
oauth.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
use mangadex_api_types::ApiClientProfile;
use serde::Deserialize;

use crate::FromResponse;

use super::AuthTokens;

#[derive(Debug, Deserialize, Clone)]
#[cfg_attr(feature = "non_exhaustive", non_exhaustive)]
#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
#[cfg_attr(feature = "specta", derive(specta::Type))]
pub struct OAuthTokenResponse {
    pub access_token: String,
    pub expires_in: u32,
    pub refresh_expires_in: u32,
    pub refresh_token: String,
    pub token_type: String,
    #[serde(default)]
    #[serde(alias = "not-before-policy")]
    pub not_before_policy: u32,
    pub session_state: uuid::Uuid,
    pub scope: String,
    pub client_type: ApiClientProfile,
}

impl From<OAuthTokenResponse> for AuthTokens {
    fn from(value: OAuthTokenResponse) -> Self {
        Self {
            session: value.access_token.to_owned(),
            refresh: value.refresh_token.clone(),
        }
    }
}

impl FromResponse for OAuthTokenResponse {
    type Response = Self;

    fn from_response(res: Self::Response) -> Self {
        res
    }
}

#[derive(Debug, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
#[cfg_attr(feature = "specta", derive(specta::Type))]
pub struct ClientInfo {
    pub client_id: String,
    pub client_secret: String,
}