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 #[cfg(feature = "unstable-msc3824")]
15 use crate::session::SsoRedirectOidcAction;
16
17 metadata! {
18 method: GET,
19 rate_limited: false,
20 authentication: NoAuthentication,
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 std::borrow::Cow;
80
81 use ruma_common::api::{
82 auth_scheme::SendAccessToken, MatrixVersion, OutgoingRequest, SupportedVersions,
83 };
84
85 use super::Request;
86
87 #[test]
88 fn serialize_sso_login_request_uri() {
89 let supported = SupportedVersions {
90 versions: [MatrixVersion::V1_1].into(),
91 features: Default::default(),
92 };
93 let req: http::Request<Vec<u8>> = Request::new("https://example.com/sso".to_owned())
94 .try_into_http_request(
95 "https://homeserver.tld",
96 SendAccessToken::None,
97 Cow::Owned(supported),
98 )
99 .unwrap();
100
101 assert_eq!(
102 req.uri().to_string(),
103 "https://homeserver.tld/_matrix/client/v3/login/sso/redirect?redirectUrl=https%3A%2F%2Fexample.com%2Fsso"
104 );
105 }
106 }
107}