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
//! Authentication endpoint
pub use refresh::{Request as Refresh, Response as RefreshResponse};
mod refresh {
use serde::{Deserialize, Serialize};
use crate::endpoints::Endpoint;
/// The response received from the Monzo API after a successful request to
/// refresh the authentication.
#[derive(Deserialize, Debug)]
pub struct Response {
/// New access token for authorising requests against the Monzo API
pub access_token: String,
/// The id of the client
#[serde(rename = "client_id")]
pub _client_id: String,
/// time (in seconds) until the access token expires
pub expires_in: i64,
/// Refresh token. This token can be used to generate a new
/// access/refresh token pair
pub refresh_token: String,
/// The token type. currently the only supported token type is
/// `bearer_auth`
#[serde(rename = "token_type")]
pub _token_type: String,
/// The id of the current Monzo user
#[serde(rename = "user_id")]
pub _user_id: String,
}
/// A request for new authentication tokens.
pub struct Request<'a> {
form: Form<'a>,
}
impl<'a> Request<'a> {
pub(crate) const fn new(
client_id: &'a str,
client_secret: &'a str,
refresh_token: &'a str,
) -> Self {
let form = Form::new(client_id, client_secret, refresh_token);
Self { form }
}
}
impl Endpoint for Request<'_> {
const AUTH_REQUIRED: bool = false;
const METHOD: reqwest::Method = reqwest::Method::POST;
fn endpoint(&self) -> &'static str {
"/oauth2/token"
}
fn form(&self) -> Option<&dyn erased_serde::Serialize> {
Some(&self.form)
}
}
#[derive(Serialize)]
struct Form<'a> {
grant_type: &'static str,
client_id: &'a str,
client_secret: &'a str,
refresh_token: &'a str,
}
impl<'a> Form<'a> {
const fn new(client_id: &'a str, client_secret: &'a str, refresh_token: &'a str) -> Self {
Self {
grant_type: "refresh_token",
client_id,
client_secret,
refresh_token,
}
}
}
}