ruma_client_api/session/
get_login_token.rs
1pub mod v1 {
6 use std::time::Duration;
11
12 use ruma_common::{
13 api::{request, response, Metadata},
14 metadata,
15 };
16
17 use crate::uiaa::{AuthData, UiaaResponse};
18
19 const METADATA: Metadata = metadata! {
20 method: POST,
21 rate_limited: true,
22 authentication: AccessToken,
23 history: {
24 unstable => "/_matrix/client/unstable/org.matrix.msc3882/login/get_token",
25 1.7 => "/_matrix/client/v1/login/get_token",
26 }
27 };
28
29 #[request(error = UiaaResponse)]
31 #[derive(Default)]
32 pub struct Request {
33 #[serde(skip_serializing_if = "Option::is_none")]
35 pub auth: Option<AuthData>,
36 }
37
38 #[response(error = UiaaResponse)]
40 pub struct Response {
41 #[serde(with = "ruma_common::serde::duration::ms", rename = "expires_in_ms")]
46 pub expires_in: Duration,
47
48 pub login_token: String,
50 }
51
52 impl Request {
53 pub fn new() -> Self {
55 Self::default()
56 }
57 }
58
59 impl Response {
60 pub fn new(expires_in: Duration, login_token: String) -> Self {
62 Self { expires_in, login_token }
63 }
64
65 pub fn with_default_expiration_duration(login_token: String) -> Self {
67 Self::new(Self::default_expiration_duration(), login_token)
68 }
69
70 fn default_expiration_duration() -> Duration {
71 Duration::from_secs(2 * 60)
73 }
74 }
75}