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