Skip to content

Extending the module

Another module can change the behavior of Visus Admin SSO Login with di.xml arguments, preferences and plugins. Use the events to react to an action. Use plugins to change an action. Refer to Events.

The presets argument of Visus\AdminSsoLogin\Service\Provider\AttributePresets adds presets, or replaces a default preset with the same code.

<type name="Visus\AdminSsoLogin\Service\Provider\AttributePresets">
<arguments>
<argument name="presets" xsi:type="array">
<item name="onelogin" xsi:type="array">
<item name="label" xsi:type="string">OneLogin</item>
<item name="mapping" xsi:type="array">
<item name="email" xsi:type="string">User.email</item>
<item name="firstname" xsi:type="string">User.FirstName</item>
<item name="lastname" xsi:type="string">User.LastName</item>
</item>
<item name="groups" xsi:type="string">memberOf</item>
<item name="note" xsi:type="string">Add the parameters to the SAML app.</item>
<item name="entity_id_patterns" xsi:type="array">
<item name="0" xsi:type="string">#^https://app\.onelogin\.com/saml/metadata/#</item>
</item>
</item>
</argument>
</arguments>
</type>
Key Description
label The name in Load Preset.
mapping The attribute of each field: email, firstname, lastname, and the additional user fields.
groups The group attribute, or empty.
note The note that the form shows with the preset.
entity_id_patterns Regular expressions. The metadata import selects the preset when the IdP entity ID matches one of them.

The example values above are examples only. Use the attribute names that your IdP sends.

The userFields argument of Visus\AdminSsoLogin\Service\Provider\Settings adds fields to Additional User Fields. The key is a column of the admin_user table. The value is the label. By default, the only field is interface_locale.

<type name="Visus\AdminSsoLogin\Service\Provider\Settings">
<arguments>
<argument name="userFields" xsi:type="array">
<item name="vendor_department" xsi:type="string" translate="true">Department</item>
</argument>
</arguments>
</type>

The module never lets an IdP attribute fill the username field.

The metadata import proposes a mapping from the attributes that the IdP lists. The aliases argument of Visus\AdminSsoLogin\Service\Provider\AttributeAliases adds names for each target: email, firstname, lastname, groups, or an additional user field. The comparison ignores case.

<type name="Visus\AdminSsoLogin\Service\Provider\AttributeAliases">
<arguments>
<argument name="aliases" xsi:type="array">
<item name="email" xsi:type="array">
<item name="0" xsi:type="string">User.email</item>
</item>
</argument>
</arguments>
</type>

The attributeNames argument of Visus\AdminSsoLogin\Service\Sso\PhishingResistance adds the names of attributes that list the authentication methods. The module reads the configured names first, then the default names.

<type name="Visus\AdminSsoLogin\Service\Sso\PhishingResistance">
<arguments>
<argument name="attributeNames" xsi:type="array">
<item name="0" xsi:type="string">urn:example:amr</item>
</argument>
</arguments>
</type>

Visus\AdminSsoLogin\Service\Sso\IdentityAttributes gives the custom attributes of the last SSO login of the current admin user.

use Visus\AdminSsoLogin\Service\Sso\IdentityAttributes;
public function __construct(private readonly IdentityAttributes $identityAttributes)
{
}
public function getDepartment(): ?string
{
return $this->identityAttributes->get('department')[0] ?? null;
}
  • getAll() returns the values of each custom attribute, by code.
  • get(string $code) returns the values of one custom attribute.

The attributes of each IdentityInterface also contains these values.

The domain verification uses Visus\AdminSsoLogin\Api\TxtLookupInterface. The default implementation is Visus\AdminSsoLogin\Service\Domain\DnsTxtLookup. To use another resolver, add a preference:

<preference for="Visus\AdminSsoLogin\Api\TxtLookupInterface"
type="Vendor\Module\Service\TxtLookup"/>

The implementation must throw Visus\AdminSsoLogin\Api\Exception\TxtLookupException when the lookup has no definitive answer. Then the verification status of the domain does not change.

Visus\AdminSsoLogin\Cron\CleanLog deletes the old entries of a log that implements Visus\AdminSsoLogin\Api\LogRetentionInterface. Each log of the module has a virtual type of CleanLog in di.xml, with the repository and the configuration path of its lifetime. Use the same pattern for a log of your own module.

These classes are good plugin points to change the result of a login:

Class Method Use
Visus\AdminSsoLogin\Service\Provider\AttributeResolver resolve Change the mapped fields, the custom attributes or the role of a login.
Visus\AdminSsoLogin\Service\Sso\UserResolver resolve, preview Change how the module finds, links or creates the admin user. preview gives the result of a provider test. Change both methods in the same way.