ruma_client_api/session/
sso_login_with_provider.rs1pub mod v3 {
6 use http::header::{LOCATION, SET_COOKIE};
11 use ruma_common::{
12 api::{request, response, Metadata},
13 metadata,
14 };
15
16 #[cfg(feature = "unstable-msc3824")]
17 use crate::session::SsoRedirectOidcAction;
18
19 const METADATA: Metadata = metadata! {
20 method: GET,
21 rate_limited: false,
22 authentication: None,
23 history: {
24 unstable => "/_matrix/client/unstable/org.matrix.msc2858/login/sso/redirect/:idp_id",
25 1.1 => "/_matrix/client/v3/login/sso/redirect/:idp_id",
26 }
27 };
28
29 #[request(error = crate::Error)]
31 pub struct Request {
32 #[ruma_api(path)]
34 pub idp_id: String,
35
36 #[ruma_api(query)]
39 #[serde(rename = "redirectUrl")]
40 pub redirect_url: String,
41
42 #[cfg(feature = "unstable-msc3824")]
48 #[ruma_api(query)]
49 #[serde(skip_serializing_if = "Option::is_none", rename = "org.matrix.msc3824.action")]
50 pub action: Option<SsoRedirectOidcAction>,
51 }
52
53 #[response(error = crate::Error, status = FOUND)]
55 pub struct Response {
56 #[ruma_api(header = LOCATION)]
58 pub location: String,
59
60 #[ruma_api(header = SET_COOKIE)]
62 pub cookie: Option<String>,
63 }
64
65 impl Request {
66 pub fn new(idp_id: String, redirect_url: String) -> Self {
68 Self {
69 idp_id,
70 redirect_url,
71 #[cfg(feature = "unstable-msc3824")]
72 action: None,
73 }
74 }
75 }
76
77 impl Response {
78 pub fn new(location: String) -> Self {
80 Self { location, cookie: None }
81 }
82 }
83
84 #[cfg(all(test, feature = "client"))]
85 mod tests {
86 use ruma_common::api::{MatrixVersion, OutgoingRequest as _, SendAccessToken};
87
88 use super::Request;
89
90 #[test]
91 fn serialize_sso_login_with_provider_request_uri() {
92 let req = Request::new("provider".to_owned(), "https://example.com/sso".to_owned())
93 .try_into_http_request::<Vec<u8>>(
94 "https://homeserver.tld",
95 SendAccessToken::None,
96 &[MatrixVersion::V1_1],
97 )
98 .unwrap();
99
100 assert_eq!(
101 req.uri().to_string(),
102 "https://homeserver.tld/_matrix/client/v3/login/sso/redirect/provider?redirectUrl=https%3A%2F%2Fexample.com%2Fsso"
103 );
104 }
105 }
106}