ruma_client_api/session/
sso_login_with_provider.rs1pub mod v3 {
6 use http::header::{LOCATION, SET_COOKIE};
11 use ruma_common::{
12 api::{auth_scheme::NoAuthentication, request, response},
13 metadata,
14 };
15
16 use crate::session::SsoRedirectAction;
17
18 metadata! {
19 method: GET,
20 rate_limited: false,
21 authentication: NoAuthentication,
22 history: {
23 unstable => "/_matrix/client/unstable/org.matrix.msc2858/login/sso/redirect/{idp_id}",
24 1.1 => "/_matrix/client/v3/login/sso/redirect/{idp_id}",
25 }
26 }
27
28 #[request(error = crate::Error)]
30 pub struct Request {
31 #[ruma_api(path)]
33 pub idp_id: String,
34
35 #[ruma_api(query)]
38 #[serde(rename = "redirectUrl")]
39 pub redirect_url: String,
40
41 #[ruma_api(query)]
43 #[serde(skip_serializing_if = "Option::is_none")]
44 pub action: Option<SsoRedirectAction>,
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(idp_id: String, redirect_url: String) -> Self {
62 Self { idp_id, redirect_url, action: None }
63 }
64 }
65
66 impl Response {
67 pub fn new(location: String) -> Self {
69 Self { location, cookie: None }
70 }
71 }
72
73 #[cfg(all(test, feature = "client"))]
74 mod tests {
75 use std::borrow::Cow;
76
77 use ruma_common::api::{
78 MatrixVersion, OutgoingRequest as _, SupportedVersions, auth_scheme::SendAccessToken,
79 };
80
81 use super::Request;
82
83 #[test]
84 fn serialize_sso_login_with_provider_request_uri() {
85 let supported = SupportedVersions {
86 versions: [MatrixVersion::V1_1].into(),
87 features: Default::default(),
88 };
89 let req = Request::new("provider".to_owned(), "https://example.com/sso".to_owned())
90 .try_into_http_request::<Vec<u8>>(
91 "https://homeserver.tld",
92 SendAccessToken::None,
93 Cow::Owned(supported),
94 )
95 .unwrap();
96
97 assert_eq!(
98 req.uri().to_string(),
99 "https://homeserver.tld/_matrix/client/v3/login/sso/redirect/provider?redirectUrl=https%3A%2F%2Fexample.com%2Fsso"
100 );
101 }
102 }
103}