Skip to content

Plugin Settings ​

You may override the default plugin settings by creating a /config/saml-sp.php file.

View the settings you can override in your project at /vendor/flipboxfactory/saml-sp/src/models/Settings.php. Each setting has a description of what it does and how to customize it.

EntityID ​

The Entity ID is the unique ID for the provider (your Craft instance) and defaults to the default site's base url. There are two Entity ID's to understand for Service Provider (again, your Craft instance) and these 2 Entity Ids must match to make things work properly.

  1. System wide Entity ID
  2. Provider Entity ID

System Wide Entity ID ​

The system wide Entity ID is the Entity ID of the current environment. You can have multiple environments which will change depending on which environment you're on (like your base url changes based on the environment).

Currently, you can edit the EntityID system wide a couple ways.

1. Add a config file in config/saml-sp.php. ​

This location lives right next to the general.php. Below is an example file contents.

php
return [
   'entityId' => 'https://my-entity-id',
];

You can also use environmental variables with Craft parser by passing it as a string.

php
return [
   'entityId' => '$ENTITY_ID',
];

2. Edit from the admin (Goto the plugin in craft, then click on the "Settings" menu item under the plugins sub nav). ​

Set the "Default Entity ID" there which will save it to the project config. Environmental variable that can be parsed by the Craft parse can also be set here (ie, $ENTITY_ID).

Provider Entity ID ​

Like the system wide Entity ID, there can be multiple providers, possibly one per environment with different configurations. These providers are saved in the database and must be static due to the configuration data share with the IdP. Provider Entity IDs can be modified on the edit page of the provider in the plugin control panel.

IdP-initiated Login ​

allowIdpInitiatedLogin (default true) accepts logins started at the IdP, such as an app tile on the IdP's dashboard. These Responses have no InResponseTo.

A Response that does have InResponseTo must answer an AuthnRequest this site sent within the last hour, and it can only be used once. If every login starts from your site, turn IdP-initiated login off:

php
// config/saml-sp.php
return [
    'allowIdpInitiatedLogin' => false,
];

Outstanding AuthnRequest IDs are stored in Craft's cache, so load-balanced sites need a shared cache (which Craft already requires).

The Response must come back to the browser session that sent the AuthnRequest. Session cookies are per host, so a login started on another host than the ACS URL's is first redirected to the ACS host.

Audience ​

Every assertion must have an AudienceRestriction that includes this site's Entity ID. If logins fail with "not a valid audience" or "no AudienceRestriction", configure the IdP's audience (Okta: "Audience URI"; Entra ID: "Identifier (Entity ID)") to match your Entity ID exactly.

Entra ID sends the audience as spn:<Entity ID> when the Identifier is the app's application ID (a bare GUID). That form is accepted automatically.

If your IdP sends some other audience you can't change, list it:

php
// config/saml-sp.php
return [
    'allowedAudiences' => ['urn:example:craft'],
];

Values must match exactly. Only list values the IdP uses for this site alone: an audience it also issues for another application would let that application's assertions log users in here.

Redirect After Login ​

After login, the user is sent to the URL in RelayState, but only when it points to this site: a path, or a URL on the current host or any Craft site's host. Anything else is ignored, and the user goes to Craft's default post-login URL.

If your frontend is on a different domain from Craft (for example a headless site), list its host names:

php
// config/saml-sp.php
return [
    'allowedRedirectHosts' => ['www.example.com'],
];

Use exact host names, without a scheme or port. Subdomains aren't included automatically.

Group Configuration/Group Assignment ​

Group Attribute Name/Group Attribute Mapping ​

Many IdPs will send groups as an attribute within the SAML Response. When configured, the plugin use that attribute to assign the user to the group properly. To achieve this, add a config/saml-sp.php then use the following configuration.

Example ​

php
return [
    // change the value as needed
    'groupAttributeNames' => [ 'groups' ]
];

Make sure the value matches the attribute name sent from the IdP.

Auto-Create Groups Removed (version 2.3.0) ​

Due to the release of Craft CMS 3.5, the project config has become more prevalant. Therefore, we've decided to remove the support for autoCreateGroups in version 2.3.0. Production environments shouldn't be saving user groups when following the project config workflow. This should be done at the lower level environments.

Please use an event as shown below.

Managing Permissions ​

Managing permissions ** is not supported ** automatically. There are a few options on how to manually manage permissions:

  1. Create the groups before implementing the plugin. Make sure you know all of the groups needed to assign the users properly.
  2. Use an event! See the EVENT_AFTER_RESPONSE_TO_USER example.