diff --git a/migrations/mysql/2021-09-16-133000_add-sso/up.sql b/migrations/mysql/2021-09-16-133000_add-sso/up.sql index 04bc34e0..fc9465c5 100644 --- a/migrations/mysql/2021-09-16-133000_add-sso/up.sql +++ b/migrations/mysql/2021-09-16-133000_add-sso/up.sql @@ -1,7 +1,7 @@ -ALTER TABLE organizations ADD COLUMN identifier TEXT NOT NULL; +ALTER TABLE organizations ADD COLUMN identifier TEXT; ALTER TABLE organizations ADD COLUMN use_sso BOOLEAN NOT NULL; ALTER TABLE organizations ADD COLUMN callback_path TEXT NOT NULL; ALTER TABLE organizations ADD COLUMN signed_out_callback_path TEXT NOT NULL; -ALTER TABLE organizations ADD COLUMN authority TEXT NOT NULL; -ALTER TABLE organizations ADD COLUMN client_id TEXT NOT NULL; -ALTER TABLE organizations ADD COLUMN client_secret TEXT NOT NULL; +ALTER TABLE organizations ADD COLUMN authority TEXT; +ALTER TABLE organizations ADD COLUMN client_id TEXT; +ALTER TABLE organizations ADD COLUMN client_secret TEXT; diff --git a/migrations/postgresql/2021-09-16-133000_add_sso/up.sql b/migrations/postgresql/2021-09-16-133000_add_sso/up.sql index 04bc34e0..fc9465c5 100644 --- a/migrations/postgresql/2021-09-16-133000_add_sso/up.sql +++ b/migrations/postgresql/2021-09-16-133000_add_sso/up.sql @@ -1,7 +1,7 @@ -ALTER TABLE organizations ADD COLUMN identifier TEXT NOT NULL; +ALTER TABLE organizations ADD COLUMN identifier TEXT; ALTER TABLE organizations ADD COLUMN use_sso BOOLEAN NOT NULL; ALTER TABLE organizations ADD COLUMN callback_path TEXT NOT NULL; ALTER TABLE organizations ADD COLUMN signed_out_callback_path TEXT NOT NULL; -ALTER TABLE organizations ADD COLUMN authority TEXT NOT NULL; -ALTER TABLE organizations ADD COLUMN client_id TEXT NOT NULL; -ALTER TABLE organizations ADD COLUMN client_secret TEXT NOT NULL; +ALTER TABLE organizations ADD COLUMN authority TEXT; +ALTER TABLE organizations ADD COLUMN client_id TEXT; +ALTER TABLE organizations ADD COLUMN client_secret TEXT; diff --git a/migrations/sqlite/2021-09-16-133000_add_sso/up.sql b/migrations/sqlite/2021-09-16-133000_add_sso/up.sql index 04bc34e0..fc9465c5 100644 --- a/migrations/sqlite/2021-09-16-133000_add_sso/up.sql +++ b/migrations/sqlite/2021-09-16-133000_add_sso/up.sql @@ -1,7 +1,7 @@ -ALTER TABLE organizations ADD COLUMN identifier TEXT NOT NULL; +ALTER TABLE organizations ADD COLUMN identifier TEXT; ALTER TABLE organizations ADD COLUMN use_sso BOOLEAN NOT NULL; ALTER TABLE organizations ADD COLUMN callback_path TEXT NOT NULL; ALTER TABLE organizations ADD COLUMN signed_out_callback_path TEXT NOT NULL; -ALTER TABLE organizations ADD COLUMN authority TEXT NOT NULL; -ALTER TABLE organizations ADD COLUMN client_id TEXT NOT NULL; -ALTER TABLE organizations ADD COLUMN client_secret TEXT NOT NULL; +ALTER TABLE organizations ADD COLUMN authority TEXT; +ALTER TABLE organizations ADD COLUMN client_id TEXT; +ALTER TABLE organizations ADD COLUMN client_secret TEXT; diff --git a/src/api/core/organizations.rs b/src/api/core/organizations.rs index 2f993773..cc76bedd 100644 --- a/src/api/core/organizations.rs +++ b/src/api/core/organizations.rs @@ -82,9 +82,9 @@ struct OrganizationSsoUpdateData { UseSso: bool, CallbackPath: String, SignedOutCallbackPath: String, - Authority: String, - ClientId: String, - ClientSecret: String, + Authority: Option, + ClientId: Option, + ClientSecret: Option, } #[derive(Deserialize, Debug)] @@ -213,7 +213,7 @@ fn post_organization( org.name = data.Name; org.billing_email = data.BillingEmail; - org.identifier = data.Identifier.unwrap_or_default(); + org.identifier = data.Identifier; org.save(&conn)?; Ok(Json(org.to_json())) diff --git a/src/api/identity.rs b/src/api/identity.rs index 8c22c5ae..b2955336 100644 --- a/src/api/identity.rs +++ b/src/api/identity.rs @@ -571,9 +571,9 @@ fn get_client_from_identifier (identifier: &str, conn: &DbConn) -> Result { let redirect = organization.callback_path.to_string(); - let client_id = ClientId::new(organization.client_id); - let client_secret = ClientSecret::new(organization.client_secret); - let issuer_url = IssuerUrl::new(organization.authority).expect("invalid issuer URL"); + let client_id = ClientId::new(organization.client_id.unwrap_or_default()); + let client_secret = ClientSecret::new(organization.client_secret.unwrap_or_default()); + let issuer_url = IssuerUrl::new(organization.authority.unwrap_or_default()).expect("invalid issuer URL"); let provider_metadata = match CoreProviderMetadata::discover(&issuer_url, http_client) { Ok(metadata) => metadata, Err(_err) => { diff --git a/src/db/models/organization.rs b/src/db/models/organization.rs index 20a19c23..7996a9ab 100644 --- a/src/db/models/organization.rs +++ b/src/db/models/organization.rs @@ -12,15 +12,15 @@ db_object! { pub uuid: String, pub name: String, pub billing_email: String, - pub identifier: String, + pub identifier: Option, pub private_key: Option, pub public_key: Option, pub use_sso: bool, pub callback_path: String, pub signed_out_callback_path: String, - pub authority: String, - pub client_id: String, - pub client_secret: String, + pub authority: Option, + pub client_id: Option, + pub client_secret: Option, } #[derive(Identifiable, Queryable, Insertable, AsChangeset)] @@ -138,13 +138,13 @@ impl Organization { billing_email, private_key, public_key, - identifier: String::from(""), + identifier: None, use_sso: false, callback_path: String::from("http://localhost/#/sso/"), signed_out_callback_path: String::from("http://localhost/#/sso/"), - authority: String::from(""), - client_id: String::from(""), - client_secret: String::from(""), + authority: None, + client_id: None, + client_secret: None, } } diff --git a/src/db/schemas/mysql/schema.rs b/src/db/schemas/mysql/schema.rs index f5caaa84..0ab35d0b 100644 --- a/src/db/schemas/mysql/schema.rs +++ b/src/db/schemas/mysql/schema.rs @@ -100,15 +100,15 @@ table! { uuid -> Text, name -> Text, billing_email -> Text, - identifier -> Text, + identifier -> Nullable, private_key -> Nullable, public_key -> Nullable, use_sso -> Bool, callback_path -> Text, signed_out_callback_path -> Text, - authority -> Text, - client_id -> Text, - client_secret -> Text, + authority -> Nullable, + client_id -> Nullable, + client_secret -> Nullable, } } diff --git a/src/db/schemas/postgresql/schema.rs b/src/db/schemas/postgresql/schema.rs index 560399b8..f7fd94f2 100644 --- a/src/db/schemas/postgresql/schema.rs +++ b/src/db/schemas/postgresql/schema.rs @@ -100,15 +100,15 @@ table! { uuid -> Text, name -> Text, billing_email -> Text, - identifier -> Text, + identifier -> Nullable, private_key -> Nullable, public_key -> Nullable, use_sso -> Bool, callback_path -> Text, signed_out_callback_path -> Text, - authority -> Text, - client_id -> Text, - client_secret -> Text, + authority -> Nullable, + client_id -> Nullable, + client_secret -> Nullable, } } diff --git a/src/db/schemas/sqlite/schema.rs b/src/db/schemas/sqlite/schema.rs index 560399b8..f7fd94f2 100644 --- a/src/db/schemas/sqlite/schema.rs +++ b/src/db/schemas/sqlite/schema.rs @@ -100,15 +100,15 @@ table! { uuid -> Text, name -> Text, billing_email -> Text, - identifier -> Text, + identifier -> Nullable, private_key -> Nullable, public_key -> Nullable, use_sso -> Bool, callback_path -> Text, signed_out_callback_path -> Text, - authority -> Text, - client_id -> Text, - client_secret -> Text, + authority -> Nullable, + client_id -> Nullable, + client_secret -> Nullable, } }