Open d--j opened 9 months ago
This frustrates me sometimes too. From what I can see, when a new provider is created for the first time, the base URL of the ACS and SLO is retrieved from Craft using \craft\helpers\UrlHelper::baseUrl()
. This typically takes the value of the @web
alias. That can be set using an environment variable in general config.
What would be ideal is if the base URL for the provider could be defined in a separate editable field. That way it could be set manually at the time of creation, without being dependent on the URL of the environment it's created in.
We have multiple environments (prod, staging, pentest) and would like to update the environments occasionally by dumping the production DB to staging/pentest. I have created a Service Provider for all environments (changing the entity ID manually so they point to the right URLs) in the production database and set the default entity ID to an environment variable that is set to the entity ID of the Service Provider for the environment in the environment's
.env
file.This all looks good – in the Provider List the correct provider gets the "(My Provider)" annotation. But the login does not work. The error log says
It only starts working when I manually save my provider in the control panel of the pentest/staging environment.
When I understand https://github.com/flipboxfactory/saml-core/blob/d97a39bb23ef0b910b78c7f7463fb5e5b11164e9/src/controllers/AbstractMetadataController.php#L69-L81 correctly this is because the cached
metadata
column of the provider includes hardcoded location URLs that point to the wrong environment (prod.example.com instead of pentest.example.com).Could https://github.com/flipboxfactory/saml-core/blob/d97a39bb23ef0b910b78c7f7463fb5e5b11164e9/src/helpers/UrlHelper.php#L87-L109 maybe use the provider's entity ID as the base URL? Or can the plugin create/refresh the descriptors part of the metadata on every request? Or could you add a console command that can trigger a metadata refresh of one or all service providers?
Is having all service providers in the production DB the best practtice you reccomand anyway? At least #144 is doing partial DB syncs (excluding the SAML tables) – but this will break the foreign key constrain of the saml_sp_provider_identity table to the users table (and if you are unlucky also the constrain of saml_sp_providers to the sites table).
Anyway my hotfix (since I would eventually forget manually saving the provider in the backend) is this console command:
It gets called with this shell script: