ruma_client_api/session/
sso_login.rs1pub mod v3 {
4 use http::header::{LOCATION, SET_COOKIE};
9 use ruma_common::{
10 api::{request, response, Metadata},
11 metadata,
12 };
13
14 #[cfg(feature = "unstable-msc3824")]
15 use crate::session::SsoRedirectOidcAction;
16
17 const METADATA: Metadata = metadata! {
18 method: GET,
19 rate_limited: false,
20 authentication: None,
21 history: {
22 1.0 => "/_matrix/client/r0/login/sso/redirect",
23 1.1 => "/_matrix/client/v3/login/sso/redirect",
24 }
25 };
26
27 #[request(error = crate::Error)]
29 pub struct Request {
30 #[ruma_api(query)]
33 #[serde(rename = "redirectUrl")]
34 pub redirect_url: String,
35
36 #[cfg(feature = "unstable-msc3824")]
42 #[ruma_api(query)]
43 #[serde(skip_serializing_if = "Option::is_none", rename = "org.matrix.msc3824.action")]
44 pub action: Option<SsoRedirectOidcAction>,
45 }
46
47 #[response(error = crate::Error, status = FOUND)]
49 pub struct Response {
50 #[ruma_api(header = LOCATION)]
52 pub location: String,
53
54 #[ruma_api(header = SET_COOKIE)]
56 pub cookie: Option<String>,
57 }
58
59 impl Request {
60 pub fn new(redirect_url: String) -> Self {
62 Self {
63 redirect_url,
64 #[cfg(feature = "unstable-msc3824")]
65 action: None,
66 }
67 }
68 }
69
70 impl Response {
71 pub fn new(location: String) -> Self {
73 Self { location, cookie: None }
74 }
75 }
76
77 #[cfg(all(test, feature = "client"))]
78 mod tests {
79 use ruma_common::api::{
80 MatrixVersion, OutgoingRequest, SendAccessToken, SupportedVersions,
81 };
82
83 use super::Request;
84
85 #[test]
86 fn serialize_sso_login_request_uri() {
87 let supported = SupportedVersions {
88 versions: [MatrixVersion::V1_1].into(),
89 features: Default::default(),
90 };
91 let req: http::Request<Vec<u8>> = Request::new("https://example.com/sso".to_owned())
92 .try_into_http_request("https://homeserver.tld", SendAccessToken::None, &supported)
93 .unwrap();
94
95 assert_eq!(
96 req.uri().to_string(),
97 "https://homeserver.tld/_matrix/client/v3/login/sso/redirect?redirectUrl=https%3A%2F%2Fexample.com%2Fsso"
98 );
99 }
100 }
101}