Skip to content

Commit

Permalink
Added SSO
Browse files Browse the repository at this point in the history
  • Loading branch information
Proziam committed Oct 12, 2024
1 parent 6a9d2f3 commit e2b7566
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Url, Error> {
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::<crate::models::SignInWithSSO>(&params)?;

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
Expand Down
17 changes: 17 additions & 0 deletions tests/client_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit e2b7566

Please sign in to comment.