SimpleSAMLphp Service Provider QuickStart
Table of Contents
This guide will describe how to configure simpleSAMLphp as a service provider (SP). You should previously have installed simpleSAMLphp as described in the simpleSAMLphp installation instructions.
The SP is configured by an entry in
This is a minimal
authsources.php for a SP:
<?php $config = array( /* This is the name of this authentication source, and will be used to access it later. */ 'default-sp' => array( 'saml:SP', ), );
For more information about additional options available for the SP, see the
If you want mulitple Service Providers in the same site and installation, you can add more entries in the
authsources.php configuration. If so remember to set the EntityID explicitly. Here is an example:
'sp1' => array( 'saml:SP', 'entityID' => 'https://sp1.example.org/', ), 'sp2' => array( 'saml:SP', 'entityID' => 'https://sp2.example.org/', ),
Some Identity Providers / Federations may require that your Service Providers holds a certificate. If you enable a certificate for your Service Provider, it may be able to sign requests and response sent to the Identity Provider, as well as receiving encrypted responses.
Create a self-signed certificate in the
cd cert openssl req -newkey rsa:2048 -new -x509 -days 3652 -nodes -out saml.crt -keyout saml.pem
Then edit your
authsources.php entry, and add references to your certificate:
'default-sp' => array( 'saml:SP', 'privatekey' => 'saml.pem', 'certificate' => 'saml.crt', ),
The service provider you are configuring needs to know about the identity providers you are going to connect to it. This is configured by metadata stored in
This is a minimal example of a
metadata/saml20-idp-remote.php metadata file:
<?php $metadata['https://openidp.feide.no'] = array( 'SingleSignOnService' => 'https://openidp.feide.no/simplesaml/saml2/idp/SSOService.php', 'SingleLogoutService' => 'https://openidp.feide.no/simplesaml/saml2/idp/SingleLogoutService.php', 'certFingerprint' => 'c9ed4dfb07caf13fc21e0fec1572047eb8a7a4cb', );
For more information about available options in the idp-remote metadata files, see the IdP remote reference.
If you have the metadata of the remote IdP as an XML file, you can use the built-in XML to simpleSAMLphp metadata converter, which by default is available as
/admin/metadata-converter.php in your simpleSAMLphp installation.
Note that the idp-remote file lists all IdPs you trust. You should remove all IdPs that you don't use.
An option in the authentication source allows you to configure which IdP should be used.
This is the
<?php $config = array( 'default-sp' => array( 'saml:SP', /* * The entity ID of the IdP this should SP should contact. * Can be NULL/unset, in which case the user will be shown a list of available IdPs. */ 'idp' => 'https://openidp.feide.no', ), );
If you do not have an IdP yourself, you could use the Feide OpenIdP to test your Service Provider. The metadata for Feide OpenIdP is already included in the metadata distributed with simpleSAMLphp.
In order to complete the connection between your SP and Feide OpenIdP, you must add the metadata for your SP to the IdP.
The metadata for your SP can be found on the
Copy the SAML 2.0 XML Metadata document automatically generated by simpleSAMLphp, and go to the OpenIdP Metadata Self-Service Registry:
You need to login with an OpenIdP account to authenticate (you can create a new account if you do not have one already). Next, click the link 'Add from SAML 2.0 XML metadata', and paste in your SAML 2.0 XML Metadata. After clicking the 'Import metadata' button, you will be presented with a form where you can edit your metadata. You can check that your metadata was parsed correctly by looking at the 'SAML 2.0' tab. The textfields for AssertionConsumerService and SingleLogoutService should contain two URLs:
After checking your metadata, give your SP a proper name and description and click 'save'.
The procedure for managing trust in federations differ, but the common part is that you would need to provide the SAML 2.0 metadata of your SP, and register that with the federation administration.
After the metadata is configured on the IdP, you should be able to test the configuration. The installation page of simpleSAMLphp has a link to test authentication sources. When you click the link, you should receive a list of authentication sources, including the one you have created for the SP.
After you click the link for that authentication source, you will be redirected to the IdP. After entering your credentials, you should be redirected back to the test page. The test page should contain a list of your attributes:
For a better looking, more advanced Discovery Service with tabs and live search, you may want to use the
in simpleSAMLphp. Take a look at the following blog entry for more information:
The API is documented in the SP API reference.
For those web resources you want to protect, you must add a few lines of PHP code:
Register the simpleSAMLphp classes with the PHP autoloader.
Require authentication of the user for those places it is required.
Access the users attributes.
We start off with loading a file which registers the simpleSAMLphp classes with the autoloader.
We select our authentication source:
$as = new SimpleSAML_Auth_Simple('default-sp');
We then require authentication:
And print the attributes:
$attributes = $as->getAttributes(); print_r($attributes);
Each attribute name can be used as an index into $attributes to obtain the value. Every attribute value is an array - a single-valued attribute is an array of a single element.
We can also request authentication with a specific IdP:
$as->login(array( 'saml:idp' => 'https://idp.example.org/', ));
Other options are also available. Take a look in the documentation for the SP module for a list of all parameters.
If you need help to make this work, or want to discuss simpleSAMLphp with other users of the software, you are fortunate: Around simpleSAMLphp there is a great Open source community, and you are welcome to join! The forums are open for you to ask questions, contribute answers other further questions, request improvements or contribute with code or plugins of your own.