Sso ​
- Type
- Class
- Namespace
- craft\services
- Inherits
- craft\services\Sso » yii\base\Component » yii\base\BaseObject
- Implements
- yii\base\Configurable
- Since
- 5.3.0
SSO service.
An instance of the service is available via Craft::$app->getSso().
Public Properties ​
| Property | Description |
|---|---|
| behaviors | yii\base\Behavior – List of behaviors attached to this component. |
| providers | craft\auth\sso\ProviderInterface[] |
providers ​
- Type
- craft\auth\sso\ProviderInterface[]
- Default value
null- Access
- Read-only
Public Methods ​
| Method | Description |
|---|---|
| __call() | Calls the named method which is not a class method. |
| __clone() | This method is called after the object is created by cloning an existing one. |
| __construct() | Constructor |
| __get() | Returns the value of a component property. |
| __isset() | Checks if a property is set, i.e. defined and not null. |
| __serialize() | Serializer |
| __set() | Sets the value of a component property. |
| __unset() | Sets a component property to be null. |
| attachBehavior() | Attaches a behavior to this component. |
| attachBehaviors() | Attaches a list of behaviors to the component. |
| behaviors() | Returns a list of behaviors that this component should behave as. |
| canGetProperty() | Returns a value indicating whether a property can be read. |
| canSetProperty() | Returns a value indicating whether a property can be set. |
| className() | Returns the fully qualified name of this class. |
| createAuthProvider() | Creates an auth provider from a given config. |
| detachBehavior() | Detaches a behavior from the component. |
| detachBehaviors() | Detaches all behaviors from the component. |
| ensureBehaviors() | Makes sure that the behaviors declared in behaviors() are attached to this component. |
| findProviderByHandle() | Returns an auth provider by its handle. |
| findUser() | Find a user based on the identity provider and identity id |
| getBehavior() | Returns the named behavior object. |
| getBehaviors() | Returns all behaviors attached to this component. |
| getProviderByHandle() | Returns an auth provider by its handle. |
| getProviders() | Return a list of all auth providers |
| hasEventHandlers() | Returns a value indicating whether there is any handler attached to the named event. |
| hasMethod() | Returns a value indicating whether a method is defined. |
| hasProperty() | Returns a value indicating whether a property is defined for this component. |
| identityExists() | Returns whether the given user ID has an associated SSO identity. |
| init() | Initializes the object. |
| linkUserToIdentity() | Assigns a user to an identity |
| loginUser() | |
| off() | Detaches an existing event handler from this component. |
| on() | Attaches an event handler to an event. |
| trigger() | Triggers an event. |
__construct() ​
Constructor
Arguments ​
$config(array)
__serialize() ​
Serializer
createAuthProvider() ​
Creates an auth provider from a given config.
Arguments ​
$config(mixed)
Returns ​
craft\auth\sso\ProviderInterface
Throws ​
findProviderByHandle() ​
Returns an auth provider by its handle.
Arguments ​
$handle(string)
Returns ​
craft\auth\sso\ProviderInterface, null
findUser() ​
Find a user based on the identity provider and identity id
Arguments ​
$provider(craft\auth\sso\ProviderInterface)$idpIdentifier(string)
Returns ​
getProviderByHandle() ​
Returns an auth provider by its handle.
Arguments ​
$handle(string)
Returns ​
craft\auth\sso\ProviderInterface
Throws ​
getProviders() ​
Return a list of all auth providers
Returns ​
craft\auth\sso\ProviderInterface[]
identityExists() ​
- Since
- 5.7.8
Returns whether the given user ID has an associated SSO identity.
Arguments ​
$userId(integer)
Returns ​
linkUserToIdentity() ​
Assigns a user to an identity
Arguments ​
$user(craft\elements\User)$provider(craft\auth\sso\ProviderInterface)$idpIdentifier(string)
Returns ​
loginUser() ​
Arguments ​
$provider(craft\auth\sso\ProviderInterface)$user(craft\elements\User)$sessionDuration(integer, null)$rememberMe(boolean)
Returns ​
Throws ​
Protected Methods ​
| Method | Description |
|---|---|
| setProviders() |
setProviders() ​
Arguments ​
$providers(craft\auth\sso\ProviderInterface[]) – List of Authorization Providers
Events ​
EVENT_POPULATE_USER ​
- Type
craft\services\UserEvent
The event that is triggered when populating a user from an SSO provider.
Example ​
php
use craft\events\UserEvent;
use craft\services\Sso;
use yii\base\Event;
Event::on(
\some\provider\Type::class,
Sso::EVENT_POPULATE_USER,
function(UserEvent $event) {
$providerData = $event->sender;
$event->user->firstName = $providerData->some_attribute;
}
);EVENT_POPULATE_USER_GROUPS ​
- Type
craft\services\UserEvent
The event that is triggered when populating user groups from an SSO provider.
Example ​
php
use craft\events\UserGroupsAssignEvent;
use craft\services\Sso;
use yii\base\Event;
Event::on(
\some\provider\Type::class,
Sso::EVENT_POPULATE_USER_GROUPS,
function(UserGroupsAssignEvent $event) {
$providerData = $event->sender;
// Assign to group 4?
if ($providerData->some_attribute === 'some_value') {
$event->groupIds[] = 4;
$event->newGroupIds[] = 4;
}
}
);