Skip to content

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->sites.

View source

Public Properties ​

PropertyDescription
behaviorsyii\base\Behavior – List of behaviors attached to this component.
providerscraft\auth\sso\ProviderInterface[]

providers ​

Type
craft\auth\sso\ProviderInterface[]
Default value
null
Access
Read-only

View source

Public Methods ​

MethodDescription
__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.
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

View source

Arguments ​

__serialize() ​

Serializer

View source

createAuthProvider() ​

Creates an auth provider from a given config.

View source

Arguments ​

  • $config (mixed)

Returns ​

craft\auth\sso\ProviderInterface

Throws ​

findProviderByHandle() ​

Returns an auth provider by its handle.

View source

Arguments ​

Returns ​

craft\auth\sso\ProviderInterface, null

findUser() ​

Find a user based on the identity provider and identity id

View source

Arguments ​

Returns ​

craft\elements\User, null

getProviderByHandle() ​

Returns an auth provider by its handle.

View source

Arguments ​

Returns ​

craft\auth\sso\ProviderInterface

Throws ​

getProviders() ​

Return a list of all auth providers

View source

Returns ​

craft\auth\sso\ProviderInterface[]

linkUserToIdentity() ​

Assigns a user to an identity

View source

Arguments ​

Returns ​

boolean

loginUser() ​

View source

Arguments ​

Returns ​

boolean

Throws ​

Protected Methods ​

MethodDescription
setProviders()

setProviders() ​

View source

Arguments ​

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;
        }
    }
);