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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//! OAuth related modules
use serde::{Deserialize, Serialize};
/// Registered application data from server.
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct AppData {
/// Application ID.
pub id: String,
/// Application name.
pub name: String,
/// Website URL of the application.
pub website: Option<String>,
/// Redirect URI for the application.
// Firefish return callbackUrl as optional string.
pub redirect_uri: Option<String>,
/// Client ID.
pub client_id: String,
/// Client secret.
pub client_secret: String,
/// Authorize URL for the application.
pub url: Option<String>,
/// Session token for Firefish.
pub session_token: Option<String>,
}
impl AppData {
/// Create a new [`AppData`].
pub fn new(
id: String,
name: String,
website: Option<String>,
redirect_uri: Option<String>,
client_id: String,
client_secret: String,
) -> Self {
Self {
id,
name,
website,
redirect_uri,
client_id,
client_secret,
url: None,
session_token: None,
}
}
}
/// Token data in server.
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct TokenData {
/// Access token for the authorized user.
pub access_token: String,
/// Token type of the access token.
pub token_type: String,
/// Scope of the access token.
// Firefish does not have scope.
pub scope: Option<String>,
/// Created date of the access token.
// Firefish does not have created_at.
pub created_at: Option<u64>,
/// Expires date of the access token.
pub expires_in: Option<u64>,
/// Refresh token of the access token.
pub refresh_token: Option<String>,
}
impl TokenData {
/// Create a new [`TokenData`].
pub fn new(
access_token: String,
token_type: String,
scope: Option<String>,
created_at: Option<u64>,
expires_in: Option<u64>,
refresh_token: Option<String>,
) -> Self {
Self {
access_token,
token_type,
scope,
created_at,
expires_in,
refresh_token,
}
}
}