aacotroneo / laravel-saml2

A Laravel 5 package for Saml2 integration as a SP (service provider) based on the simple OneLogin toolkit
MIT License
567 stars 238 forks source link

[Question] How to handle multi-tenancy? #246

Open gopalkriagg opened 3 years ago

gopalkriagg commented 3 years ago

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.

nbyloff commented 3 years ago

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']
      ]);
  }
}