Events
The module dispatches Magento events for its single sign-on actions. The constants are in Visus\AdminSsoLogin\Api\EventsInterface.
The events tell observers what happened. To change what the module does, such as the attributes or the role of a login, use a plugin. Refer to Extending the module.
Event list
Section titled “Event list”| Constant | Event name |
|---|---|
LOGIN_SUCCESS |
visus_admin_sso_login_success |
LOGIN_FAILURE |
visus_admin_sso_login_failure |
USER_RESOLVE_AFTER |
visus_admin_sso_user_resolve_after |
REAUTH_AFTER |
visus_admin_sso_reauth_after |
API_TOKEN_ISSUED |
visus_admin_sso_api_token_issued |
API_TOKEN_REVOKED |
visus_admin_sso_api_token_revoked |
visus_admin_sso_login_success
Section titled “visus_admin_sso_login_success”An SSO login logged an admin user in.
| Key | Type |
|---|---|
user |
Magento\User\Model\User |
provider |
Visus\AdminSsoLogin\Api\Data\ProviderInterface |
name_id |
string |
email |
string|null |
attributes |
Visus\AdminSsoLogin\Service\Provider\ResolvedAttributes |
is_phishing_resistant |
bool |
The Magento event backend_auth_user_login_success also fires, before this event, with the user only.
visus_admin_sso_login_failure
Section titled “visus_admin_sso_login_failure”The module refused an SSO login. The Magento event backend_auth_user_login_failed does not fire for an SSO login.
| Key | Type |
|---|---|
provider |
ProviderInterface|null. Null when the ACS URL names no active provider. |
name_id |
string|null. Unverified when the response failed its checks. |
email |
string|null |
admin_user_id |
int|null. The admin user of the login, when the module found one. |
reason |
string |
visus_admin_sso_user_resolve_after
Section titled “visus_admin_sso_user_resolve_after”An SSO login found, linked or created its admin user, and copied the fields of the IdP to the user. The event fires before the module checks that the user may log in. A test of a provider does not dispatch this event.
| Key | Type |
|---|---|
user |
Magento\User\Model\User |
identity |
Visus\AdminSsoLogin\Api\Data\IdentityInterface, with the custom attributes of the login |
provider |
ProviderInterface |
attributes |
ResolvedAttributes |
is_new |
bool. True when the login created the admin user. |
is_role_changed |
bool. True when the login changed the role of the admin user. |
is_linked |
bool. True when the login linked an existing admin user to the provider for the first time, and replaced its password with a random one. |
visus_admin_sso_reauth_after
Section titled “visus_admin_sso_reauth_after”A logged-in admin user verified their identity again at their IdP, or failed to.
The event reports the checks of the response. The completion page can still refuse a verified result: a session that logged in with a phishing-resistant method needs a phishing-resistant re-authentication too. For a refused result, the event and the login log show a success, and the admin session receives no proof.
| Key | Type |
|---|---|
result |
Visus\AdminSsoLogin\Service\Sso\ReauthResult |
admin_user_id |
int |
provider_id |
int|null |
visus_admin_sso_api_token_issued
Section titled “visus_admin_sso_api_token_issued”The module issued an admin API token to an SSO-managed admin user.
| Key | Type |
|---|---|
admin_user_id |
int |
provider_id |
int|null |
expires_at |
DateTimeImmutable, in UTC |
visus_admin_sso_api_token_revoked
Section titled “visus_admin_sso_api_token_revoked”The module revoked all admin API tokens of an admin user.
| Key | Type |
|---|---|
admin_user_id |
int |
The ResolvedAttributes object
Section titled “The ResolvedAttributes object”| Property | Type | Description |
|---|---|---|
userFields |
array<string,string> |
The value of each mapped admin user field that the assertion has. |
customAttributes |
array<string,string[]> |
The values of each custom attribute that the assertion has. |
roleId |
int|null |
The role of the first rule that matches, or else the default role of the provider. |
isRoleMatched |
bool |
True if a role rule matched. |
isDenied |
bool |
True if the provider denies a user that matches no rule, and no rule matched. |
isRoleSynced |
bool |
True if the role applies at each login, and not only to a created user. |
Model events
Section titled “Model events”The models of the module also dispatch the save and delete events of Magento, with the prefix visus_admin_sso_. An example is visus_admin_sso_provider_save_after.
Some changes write the table directly, and dispatch no model event. Examples are the verification of a domain, the password that a login replaces, and the change logs that the database triggers write.
Example observer
Section titled “Example observer”-
Declare the observer in
etc/events.xmlof your module:<?xml version="1.0"?><config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd"><event name="visus_admin_sso_login_success"><observer name="vendor_module_sso_login_notice"instance="Vendor\Module\Observer\SsoLoginNotice"/></event></config> -
Write the observer class:
<?phpdeclare(strict_types=1);namespace Vendor\Module\Observer;use Magento\Framework\Event\Observer;use Magento\Framework\Event\ObserverInterface;use Psr\Log\LoggerInterface;class SsoLoginNotice implements ObserverInterface{public function __construct(private readonly LoggerInterface $logger){}public function execute(Observer $observer): void{$user = $observer->getData('user');$provider = $observer->getData('provider');$this->logger->info('SSO login', ['user_id' => (int)$user->getId(),'provider' => $provider->getCode(),'phishing_resistant' => (bool)$observer->getData('is_phishing_resistant'),]);}} -
Run
bin/magento setup:di:compilein production mode, and clean the cache.