Skip to content

Commit

Permalink
Test cleanup
Browse files Browse the repository at this point in the history
Added SignInWithSSO Model

Added SSOSignInOptions

Added SSOSuccess
  • Loading branch information
Proziam committed Oct 10, 2024
1 parent d6bc2b4 commit bb86c15
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 14 deletions.
9 changes: 6 additions & 3 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ use crate::{
models::{
AuthClient, AuthServerHealth, AuthServerSettings, LogoutScope, Provider,
RefreshSessionPayload, RequestMagicLinkPayload, ResendParams, ResetPasswordForEmailPayload,
SSOResponse, Session, SignInEmailOtpParams, SignInWithEmailAndPasswordPayload,
Session, SignInEmailOtpParams, SignInWithEmailAndPasswordPayload,
SignInWithEmailOtpPayload, SignInWithIdTokenCredentials, SignInWithOAuthOptions,
SignInWithPhoneAndPasswordPayload, SignInWithSSO, SignUpWithEmailAndPasswordPayload,
SignUpWithPhoneAndPasswordPayload, UpdateUserPayload, User, VerifyOtpParams,
},
};

const AUTH_V1: &str = "/auth/v1";

impl AuthClient {
/// Create a new Auth Client
/// You can find your project url and keys at https://supabase.com/dashboard/project/<your project id>/settings/api
Expand Down Expand Up @@ -84,8 +86,8 @@ impl AuthClient {
let response = self
.client
.post(format!(
"{}/auth/v1/token?grant_type=password",
self.project_url
"{}{}/token?grant_type=password",
self.project_url, AUTH_V1
))
.headers(headers)
.body(body)
Expand Down Expand Up @@ -685,6 +687,7 @@ impl AuthClient {
Ok(response)
}

// WARN: Untested, requires a SAML 2.0 Provider and Supabase Pro plan
/// Get the project URL from an AuthClient
pub fn project_url(&self) -> &String {
&self.project_url
Expand Down
27 changes: 27 additions & 0 deletions src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,33 @@ pub enum LogoutScope {
Others,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct SignInWithSSO {
#[serde(skip_serializing_if = "Option::is_none")]
pub provider_id: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub domain: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub options: Option<SSOSignInOptions>,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct SSOSignInOptions {
#[serde(skip_serializing_if = "Option::is_none")]
captcha_token: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
redirect_to: Option<String>,
}


#[derive(Debug, Serialize, Deserialize)]
pub struct SSOSuccess {
pub url: String,
pub status: u16,
pub headers: Headers,
}

#[derive(Debug, Serialize, Deserialize)]
// Implement custom Debug to avoid exposing sensitive information
impl fmt::Debug for AuthClient {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
Expand Down
22 changes: 11 additions & 11 deletions tests/client_tests.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::{collections::HashMap, env};

use supabase_auth::models::{
AuthClient, DesktopResendParams, LogoutScope, ResendParams, SignInWithOAuthOptions,
UpdateUserPayload,
AuthClient, DesktopResendParams, LogoutScope, ResendParams, SSOSignInOptions, SSOSuccess,
SignInWithOAuthOptions, SignInWithSSO, UpdateUserPayload,
};

fn create_test_client() -> AuthClient {
Expand All @@ -24,7 +24,7 @@ async fn test_login_with_email() {
let demo_password = "qwerqwer";

let session = auth_client
.sign_in_with_email_and_password(demo_email.as_ref(), demo_password)
.login_with_email(demo_email.as_ref(), demo_password)
.await
.unwrap();

Expand All @@ -39,7 +39,7 @@ async fn test_login_with_email_invalid() {
let demo_password = "invalid";

let session = auth_client
.sign_in_with_email_and_password(demo_email, demo_password)
.login_with_email(demo_email, demo_password)
.await;

assert!(session.is_err())
Expand Down Expand Up @@ -147,7 +147,7 @@ async fn sign_in_with_oauth_test() {
let demo_password = "qwerqwer";

let session = auth_client
.sign_in_with_email_and_password(demo_email.as_ref(), demo_password)
.login_with_email(demo_email.as_ref(), demo_password)
.await;

if session.is_err() {
Expand Down Expand Up @@ -185,7 +185,7 @@ async fn sign_in_with_oauth_no_options_test() {
let demo_password = "qwerqwer";

let session = auth_client
.sign_in_with_email_and_password(demo_email.as_ref(), demo_password)
.login_with_email(demo_email.as_ref(), demo_password)
.await;

if session.is_err() {
Expand Down Expand Up @@ -217,7 +217,7 @@ async fn get_user_test() {
let demo_password = "qwerqwer";

let session = auth_client
.sign_in_with_email_and_password(demo_email.as_ref(), demo_password)
.login_with_email(demo_email.as_ref(), demo_password)
.await;

if session.is_err() {
Expand All @@ -241,7 +241,7 @@ async fn update_user_test() {
let demo_password = "qwerqwer";

let session = auth_client
.sign_in_with_email_and_password(demo_email.as_ref(), demo_password)
.login_with_email(demo_email.as_ref(), demo_password)
.await;

if session.is_err() {
Expand All @@ -266,7 +266,7 @@ async fn update_user_test() {
let test_password = "qqqqwwww";

let new_session = auth_client
.sign_in_with_email_and_password(demo_email.as_ref(), test_password)
.login_with_email(demo_email.as_ref(), test_password)
.await;

if new_session.is_err() {
Expand Down Expand Up @@ -295,7 +295,7 @@ async fn exchange_token_for_session() {
let demo_password = "qwerqwer";

let original_session = auth_client
.sign_in_with_email_and_password(demo_email.as_ref(), demo_password)
.login_with_email(demo_email.as_ref(), demo_password)
.await
.unwrap();

Expand Down Expand Up @@ -360,7 +360,7 @@ async fn logout_test() {
let demo_password = "qwerqwer";

let session = auth_client
.sign_in_with_email_and_password(demo_email, demo_password.to_string())
.login_with_email(demo_email, demo_password.to_string())
.await
.unwrap();

Expand Down

0 comments on commit bb86c15

Please sign in to comment.