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
pub mod v3 {
use http::header::LOCATION;
use ruma_common::{
api::{request, response, Metadata},
metadata,
};
const METADATA: Metadata = metadata! {
method: GET,
rate_limited: false,
authentication: None,
history: {
1.0 => "/_matrix/client/r0/login/sso/redirect",
1.1 => "/_matrix/client/v3/login/sso/redirect",
}
};
#[request(error = crate::Error)]
pub struct Request {
#[ruma_api(query)]
#[serde(rename = "redirectUrl")]
pub redirect_url: String,
}
#[response(error = crate::Error)]
pub struct Response {
#[ruma_api(header = LOCATION)]
pub location: String,
}
impl Request {
pub fn new(redirect_url: String) -> Self {
Self { redirect_url }
}
}
impl Response {
pub fn new(location: String) -> Self {
Self { location }
}
}
#[cfg(all(test, feature = "client"))]
mod tests {
use ruma_common::api::{MatrixVersion, OutgoingRequest, SendAccessToken};
use super::Request;
#[test]
fn serialize_sso_login_request_uri() {
let req: http::Request<Vec<u8>> =
Request { redirect_url: "https://example.com/sso".to_owned() }
.try_into_http_request(
"https://homeserver.tld",
SendAccessToken::None,
&[MatrixVersion::V1_1],
)
.unwrap();
assert_eq!(
req.uri().to_string(),
"https://homeserver.tld/_matrix/client/v3/login/sso/redirect?redirectUrl=https%3A%2F%2Fexample.com%2Fsso"
);
}
}
}