laravel-saml2 icon indicating copy to clipboard operation
laravel-saml2 copied to clipboard

[Question] How to handle multi-tenancy?

Open gopalkriagg opened this issue 3 years ago • 1 comments

First of all, thank you for making such a great package!!

The Laravel application that I work on serves multiple companies (tenants) and each of these companies get a unique subdomain. So, all the requests coming from a tenant have their unique subdomain attached to the request URL. Now, we are creating a feature which will allow each of these companies to configure an IdP if they want to use SAML feature. I was thinking that we will allow the admins of each tenant to configure such settings from admin panel and these settings will be stored in the SQL database in saml_settings table which will have one to one relationship with tenants table.

But since the settings are picked from <idpName>_idp_settings.php and not from the database I am not sure how to configure this. I don't want to add a new <idpName>_idp_settings.php file and then release the app, whenever a new tenant wants to use this feature.

Sorry for such a long explanation.

I have looked around in the issues of this repo but couldn't find the exact answer that I am looking for. Please help.

gopalkriagg avatar Jun 10 '21 06:06 gopalkriagg

I was looking for the same thing, but it's coded for file based configs only.

I don't have a lot of idp(s) expected so I will just use config files, but you could try using a ServiceProvider to load idp settings into the config directly to match this packages expected format. Something like...

/**
 * Bootstrap any application services.
 *
 * @return void
 */
public function boot() 
{
  $all = SamlSetting::all();
  foreach ($all as $setting) {
    config([
        ''saml2.'.$setting->idpName.'_idp_settings'' => ['key' => 'value']
      ]);
  }
}

nbyloff avatar Sep 14 '21 18:09 nbyloff