Open MichMich opened 1 month ago
This seems really sucks but worked 🤔
$ php artisan db
mysql> update saml2_tenants set uuid='okta' where id=1;
Then all urls are now under /saml2/okta/[...]
Yeah that probably works but seems like a dirty hack. Thanks for the suggestion though.
This would be relatively simple to add with a unique slug
field. I did just that using the metadata
field.
1 - Add a unique constraint to metadata->>slug
(this is using Postgres):
create unique index saml2_tenants_metadata_slug_idx
on public.saml2_tenants ((metadata ->> 'slug'::text));
2 - Create some route in your application such as /sso/{tenant_slug}/login
3 - In the controller, fetch the tenant by the metadata->>slug
field and redirect to the UUID route.
Currently, tenants (SAML providers) are registered via Artisan commands and can be accessed through URLs like:
/saml2/b2dae2e6-e814-4553-a3a5-a56ddaca1110/login
While this works, I would prefer to use a more friendly identifier (such as a key) in the URLs, like:
/saml2/okta/login
To achieve this, I created a custom middleware that attempts to resolve the tenant by the friendly key and then falls back to the default UUID-based behavior if the key is not found. Here’s the code I used:
I also overrode the
saml2.resolveTenant
middleware in bootstrap/app.php like so:Question:
Is there a cleaner or more integrated way to accomplish this, or perhaps a feature that could be added to the package to support friendly keys natively?
Thanks for your work on this package, and I appreciate any insights you might have!