-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathauth.rs
More file actions
167 lines (149 loc) · 4.42 KB
/
auth.rs
File metadata and controls
167 lines (149 loc) · 4.42 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
use crate::types::common::{Amount, Interval, Receiver};
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(tag = "type", rename_all = "kebab-case")]
pub enum AccessItem {
#[serde(rename = "incoming-payment")]
IncomingPayment {
actions: Vec<IncomingPaymentAction>,
#[serde(skip_serializing_if = "Option::is_none")]
identifier: Option<String>,
},
#[serde(rename = "outgoing-payment")]
OutgoingPayment {
actions: Vec<OutgoingPaymentAction>,
identifier: String,
#[serde(skip_serializing_if = "Option::is_none")]
limits: Option<LimitsOutgoing>,
},
#[serde(rename = "quote")]
Quote { actions: Vec<QuoteAction> },
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "kebab-case")]
pub enum IncomingPaymentAction {
Create,
Complete,
Read,
ReadAll,
List,
ListAll,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "kebab-case")]
pub enum OutgoingPaymentAction {
Create,
Read,
ReadAll,
List,
ListAll,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "kebab-case")]
pub enum QuoteAction {
Create,
Read,
ReadAll,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct LimitsOutgoing {
#[serde(skip_serializing_if = "Option::is_none")]
pub receiver: Option<Receiver>,
#[serde(skip_serializing_if = "Option::is_none")]
pub debit_amount: Option<Amount>,
#[serde(skip_serializing_if = "Option::is_none")]
pub receive_amount: Option<Amount>,
#[serde(skip_serializing_if = "Option::is_none")]
pub interval: Option<Interval>,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct AccessToken {
pub value: String,
pub manage: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub expires_in: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub access: Option<Vec<AccessItem>>,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct AccessTokenResponse {
pub access_token: AccessToken,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct GrantRequest {
pub access_token: AccessTokenRequest,
pub(crate) client: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub interact: Option<InteractRequest>,
}
impl GrantRequest {
pub fn new(access_token: AccessTokenRequest, interact: Option<InteractRequest>) -> Self {
Self {
access_token,
client: String::new(), // Will be set by the client internally
interact,
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct AccessTokenRequest {
pub access: Vec<AccessItem>,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct InteractRequest {
pub start: Vec<String>,
pub finish: Option<InteractFinish>,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct InteractFinish {
pub method: String,
pub uri: String,
pub nonce: String,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct InteractResponse {
pub redirect: String,
pub finish: String,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct Continue {
pub access_token: ContinueAccessToken,
pub uri: String,
pub wait: Option<i64>,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct ContinueAccessToken {
pub value: String,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(untagged)]
pub enum GrantResponse {
WithInteraction {
interact: InteractResponse,
#[serde(rename = "continue")]
continue_: Continue,
},
WithToken {
access_token: AccessToken,
#[serde(rename = "continue")]
continue_: Continue,
},
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct ContinueRequest {
pub interact_ref: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(untagged)]
pub enum ContinueResponse {
WithToken {
access_token: AccessToken,
#[serde(rename = "continue")]
continue_: Continue,
},
Pending {
#[serde(rename = "continue")]
continue_: Continue,
},
}