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