Skip to content

Service contracts

The Visus\AdminSsoLogin\Api namespace contains the service contracts of the module. These interfaces have the @api annotation. Use them instead of the models and the resource models.

The repositories validate each save. For example, ProviderRepositoryInterface::save() calls the provider validator. Thus a save through the admin forms, or through code that uses the repository, passes the same checks.

Interface Purpose Methods
ProviderRepositoryInterface The SAML identity providers. save, getById, getByCode, getList, delete, deleteById
DomainRepositoryInterface The email domains that must log in through SSO. getByDomain and getByEmail return only a verified domain. save, getById, getByDomain, getByEmail, getList, delete, deleteById
IdentityRepositoryInterface The links between SAML NameIDs and admin users. save, getById, getByProviderAndNameId, getByProviderAndAdminUser, getList, delete, deleteById
ServiceProviderKeyRepositoryInterface The service provider key pairs. getSigningList returns the active keys that have not expired. save, getById, getActiveList, getSigningList, delete, deleteById
LoginLogRepositoryInterface The SSO login log. save, getList, deleteOlderThan
ProviderLogRepositoryInterface The provider change log. Database triggers write the entries, so there is no save method. getList, deleteOlderThan
DomainLogRepositoryInterface The domain change log. getList, deleteOlderThan
ServiceProviderKeyLogRepositoryInterface The service provider key change log. getList, deleteOlderThan
AuthnRequestRepositoryInterface The SAML AuthnRequest records that wait for a response. save, get, consume, deleteExpired
AssertionRegistryInterface The used assertions. The registry prevents a second use of an assertion. register, deleteExpired
Interface Purpose
EventsInterface The names of the events. Refer to Events.
LogRetentionInterface A log from which the module can delete old entries, with deleteOlderThan(int $days).
TxtLookupInterface Reads the TXT records of a host name from the DNS, with getRecords(string $host).

The Api\Data namespace has a data interface and a search results interface for each entity:

  • ProviderInterface, ProviderSearchResultsInterface
  • DomainInterface, DomainSearchResultsInterface
  • IdentityInterface, IdentitySearchResultsInterface
  • ServiceProviderKeyInterface
  • AuthnRequestInterface
  • LoginLogInterface, LoginLogSearchResultsInterface
  • ProviderLogInterface, ProviderLogSearchResultsInterface
  • DomainLogInterface, DomainLogSearchResultsInterface
  • ServiceProviderKeyLogInterface, ServiceProviderKeyLogSearchResultsInterface

Example: read the identities of a provider

Section titled “Example: read the identities of a provider”
use Magento\Framework\Api\SearchCriteriaBuilder;
use Visus\AdminSsoLogin\Api\IdentityRepositoryInterface;
use Visus\AdminSsoLogin\Api\ProviderRepositoryInterface;
class IdentityReport
{
public function __construct(
private readonly ProviderRepositoryInterface $providerRepository,
private readonly IdentityRepositoryInterface $identityRepository,
private readonly SearchCriteriaBuilder $searchCriteriaBuilder
) {
}
/**
* @return string[] The email address of each identity, by admin user ID.
*/
public function getEmails(string $providerCode): array
{
$provider = $this->providerRepository->getByCode($providerCode);
$criteria = $this->searchCriteriaBuilder
->addFilter('provider_id', $provider->getProviderId())
->create();
$emails = [];
foreach ($this->identityRepository->getList($criteria)->getItems() as $identity) {
$emails[$identity->getAdminUserId()] = (string)$identity->getEmail();
}
return $emails;
}
}