Using SimpleSAMLphp with Drupal 10
- 10 minute read
-
Co-authored by Brandon Goodwin and Sidhartha Sharma
Installing Simplesamlphp_auth
-
To install the SimpleSAMLphp authentication module, run the following command:
-
Enable the SimpleSAMLphp Authentication module and add the External Authentication module as a dependency.
Creating the Symlink
Create a symbolic link in the docroot to access SimpleSAMLphp from the web:
Setting up Configuration Directories
-
In your project root, create a directory simplesamlphp_files.
-
Copy the configuration template files from the vendor/simplesamlphp/simplesamlphp directory:
- In Config:
- In Metadata:
Configuring Environment Variables
Alternatively, you can use an environment variable to dictate where your configuration lives for simplesaml. For Cloud IDE, follow these steps: https://docs.acquia.com/acquia-cloud-platform/add-ons/ide/faq#section-how-can-i-set-a-custom-environment-variable-to-use-with-my-application
- SIMPLESAMLPHP_CONFIG_DIR: /var/www/html/simplesamlphp_files/config
- Acquia Cloud Next Env:
- Acquia Cloud Classic Env:
- Acquia Cloud IDE:
Modifying Config.php
-
In your config directory create a file named acquia_config.php.This file will be used to override some of the settings in config.php, and provide modifications that are unique to your Acquia environment
- Including acquia_config.php with your config.php
- To append it to your config manually:
- Or add this snippet to the bottom of your config.php:
Updating .htaccess
In your .htaccess, add the following snippet to prevent a permission denied error on the simplesaml path:
- Ensure that you add it after the following line:
- Ensure that you add it before the following line:
Configuring acquia_config.php
- In your newly created acquia_config.php, insert the following:
Editing acquia_config.php
Within our acquia_config.php edit the following sections
- Technical Contact Name & Email
- Secret Salt and auth admin password
- Generate Secret Salt
- Generate auth admin password
Note: Depending on where you are setting this up (Acquia Cloud or Local), you may need to change the tempdir or loggingdir to an existing path.
Configuring authsources.php
- Next, provide information about your service provider (SP) and identity provider (IdP) to SimpleSAMLphp in an authsources.php file, which configures the service provider.
- The values in the authsources.php file control the following settings:
- Entity ID of your SP, which is a unique identifier for your SP. This value defaults to the URL of the service provider’s metadata. You may want to override this value with a more human-readable name.
- Entity ID of your IdP, which is a unique identifier for your IdP. This value must match the entity ID value in the metadata provided to you by your IdP.
- The NameIDFormat, which your IdP includes in its metadata.
- The location of a self-signed SSL certificate, if your IdP requires your service provider to have a self-signed SSL certificate.
- Previously in this tutorial, we created a copy of the authsources template, but we also provide an example file here: https://docs.acquia.com/downloadable-resources?cid=3e60e#section-authsourcesphp
- Replace the entityID to a unique identifier (Your domain name is fine in this case)
- Replace the idp with the metadata url provided by your idp
Setting up SSL Certificates (If Required)
If your IdP requires an SSL cert for authentication, create a cert directory under the simplesamlphp_files directory and place both the cert and private key in that location:
-
Create the cert directory:
- Create Cert and Private Key:
Configuring saml20-idp-remote.php
-
Given the metadata XML file provided by your IDP, navigate to /simplesaml/module.php/admin/federation/metadata-converter.
-
Press parse. It outputs the proper input for saml20-idp-remote file.
Verifying Installation
- Access SimpleSAMLphp Admin Interface: Visit
https://your-domain.com/simplesaml/admin
to access the SimpleSAMLphp admin interface. You must see the SimpleSAMLphp dashboard if everything is configured correctly. - Run SimpleSAMLphp Diagnostics: Use the diagnostic tools within the admin interface to check the configuration, especially the connection between your Service Provider (SP) and Identity Provider (IdP).
Common Issues and Troubleshooting
- Symlink Issues: Ensure the symlinks are correctly created and point to the correct directories. If SimpleSAMLphp is not accessible, check the symlink paths.
- Permission Errors: If you encounter permission denied errors, verify the file and directory permissions for
simplesamlphp_files
and its contents. All files should be readable by the web server. - Configuration Errors: Double-check the
config.php
andauthsources.php
for syntax errors or incorrect paths. - Memcache issues: For Cloud Next environments, you must not store SimpleSAML sessions in Memcache but use database instead.
Useful References and Resources
- SimpleSAMLphp Documentation: SimpleSAMLphp Documentation
- Drupal SimpleSAMLphp Module Documentation: Drupal SimpleSAMLphp Module