diff --git a/src/client.rs b/src/client.rs index 151f1b3..39b1eb1 100644 --- a/src/client.rs +++ b/src/client.rs @@ -688,6 +688,35 @@ impl AuthClient { } // WARN: Untested, requires a SAML 2.0 Provider and Supabase Pro plan + pub async fn sso(&self, params: SignInWithSSO) -> Result { + let mut headers = HeaderMap::new(); + headers.insert(CONTENT_TYPE, HeaderValue::from_static("application/json")); + headers.insert("apikey", HeaderValue::from_str(&self.api_key)?); + + let body = serde_json::to_string::(¶ms)?; + + let response = self + .client + .post(&format!("{}{}/sso", self.project_url, AUTH_V1)) + .headers(headers) + .body(body) + .send() + .await?; + + let res_status = response.status(); + let url = response.url().clone(); + let res_body = response.text().await?; + + if res_status.is_server_error() || res_status.is_client_error() { + return Err(crate::error::Error::AuthError { + status: res_status, + message: res_body, + }); + } + + Ok(url) + } + /// Get the project URL from an AuthClient pub fn project_url(&self) -> &String { &self.project_url diff --git a/tests/client_tests.rs b/tests/client_tests.rs index 5f3a1cb..30e1d65 100644 --- a/tests/client_tests.rs +++ b/tests/client_tests.rs @@ -373,6 +373,23 @@ async fn logout_test() { assert!(logout.status().is_success()) } +#[tokio::test] +async fn test_sso_login() { + let auth_client = create_test_client(); + let demo_domain = env::var("DEMO_DOMAIN").unwrap(); + let params = SignInWithSSO { + domain: Some(demo_domain), + options: None, + provider_id: None, + }; + + let ssoresponse = auth_client.sso(params).await.unwrap(); + + println!("{:?}", ssoresponse.to_string()); + + assert!(ssoresponse.to_string().len() > 1); +} + #[tokio::test] async fn get_settings_test() { let auth_client = create_test_client();