ruma_client_api/session/
sso_login.rs
1pub 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::{MatrixVersion, OutgoingRequest, SendAccessToken};
80
81 use super::Request;
82
83 #[test]
84 fn serialize_sso_login_request_uri() {
85 let req: http::Request<Vec<u8>> = Request::new("https://example.com/sso".to_owned())
86 .try_into_http_request(
87 "https://homeserver.tld",
88 SendAccessToken::None,
89 &[MatrixVersion::V1_1],
90 )
91 .unwrap();
92
93 assert_eq!(
94 req.uri().to_string(),
95 "https://homeserver.tld/_matrix/client/v3/login/sso/redirect?redirectUrl=https%3A%2F%2Fexample.com%2Fsso"
96 );
97 }
98 }
99}