W3cubDocs

/Yii 2.0

Class yii\authclient\AuthAction

Inheritance yii\authclient\AuthAction » yii\base\Action » yii\base\Component » yii\base\Object
Implements yii\base\Configurable
Available since version 2.0
Source Code https://github.com/yiisoft/yii2-authclient/blob/master/AuthAction.php

AuthAction performs authentication via different auth clients.

It supports yii\authclient\OpenId, yii\authclient\OAuth1 and yii\authclient\OAuth2 client types.

Usage:

class SiteController extends Controller
{
    public function actions()
    {
        return [
            'auth' => [
                'class' => 'yii\authclient\AuthAction',
                'successCallback' => [$this, 'successCallback'],
            ],
        ]
    }

    public function successCallback($client)
    {
        $attributes = $client->getUserAttributes();
        // user login or signup comes here
    }
}

Usually authentication via external services is performed inside the popup window. This action handles the redirection and closing of popup window correctly.

See also:

Public Properties

Property Type Description Defined By
$behaviors yii\base\Behavior[] List of behaviors attached to this component yii\base\Component
$cancelUrl string Cancel URL. yii\authclient\AuthAction
$clientCollection string Name of the auth client collection application component. yii\authclient\AuthAction
$clientIdGetParamName string Name of the GET param, which is used to passed auth client id to this action. yii\authclient\AuthAction
$controller yii\base\Controller|yii\web\Controller The controller that owns this action yii\base\Action
$id string ID of the action yii\base\Action
$redirectView string Name or alias of the view file, which should be rendered in order to perform redirection. yii\authclient\AuthAction
$successCallback callable PHP callback, which should be triggered in case of successful authentication. yii\authclient\AuthAction
$successUrl string Successful URL. yii\authclient\AuthAction
$uniqueId string The unique ID of this action among the whole application. yii\base\Action

Public Methods

Method Description Defined By
__call() Calls the named method which is not a class method. yii\base\Object
__clone() This method is called after the object is created by cloning an existing one. yii\base\Component
__construct() Constructor. yii\base\Action
__get() Returns the value of an object property. yii\base\Object
__isset() Checks if a property is set, i.e. defined and not null. yii\base\Object
__set() Sets value of an object property. yii\base\Object
__unset() Sets an object property to null. yii\base\Object
attachBehavior() Attaches a behavior to this component. yii\base\Component
attachBehaviors() Attaches a list of behaviors to the component. yii\base\Component
behaviors() Returns a list of behaviors that this component should behave as. yii\base\Component
canGetProperty() Returns a value indicating whether a property can be read. yii\base\Object
canSetProperty() Returns a value indicating whether a property can be set. yii\base\Object
className() Returns the fully qualified name of this class. yii\base\Object
detachBehavior() Detaches a behavior from the component. yii\base\Component
detachBehaviors() Detaches all behaviors from the component. yii\base\Component
ensureBehaviors() Makes sure that the behaviors declared in behaviors() are attached to this component. yii\base\Component
getBehavior() Returns the named behavior object. yii\base\Component
getBehaviors() Returns all behaviors attached to this component. yii\base\Component
getCancelUrl() yii\authclient\AuthAction
getSuccessUrl() yii\authclient\AuthAction
getUniqueId() Returns the unique ID of this action among the whole application. yii\base\Action
hasEventHandlers() Returns a value indicating whether there is any handler attached to the named event. yii\base\Component
hasMethod() Returns a value indicating whether a method is defined. yii\base\Object
hasProperty() Returns a value indicating whether a property is defined. yii\base\Object
init() Initializes the object. yii\base\Object
off() Detaches an existing event handler from this component. yii\base\Component
on() Attaches an event handler to an event. yii\base\Component
redirect() Redirect to the given URL or simply close the popup window. yii\authclient\AuthAction
redirectCancel() Redirect to the $cancelUrl or simply close the popup window. yii\authclient\AuthAction
redirectSuccess() Redirect to the URL. If URL is null, $successUrl will be used. yii\authclient\AuthAction
run() Runs the action. yii\authclient\AuthAction
runWithParams() Runs this action with the specified parameters. yii\base\Action
setCancelUrl() yii\authclient\AuthAction
setSuccessUrl() yii\authclient\AuthAction
trigger() Triggers an event. yii\base\Component

Protected Methods

Method Description Defined By
afterRun() This method is called right after run() is executed. yii\base\Action
auth() Perform authentication for the given client. yii\authclient\AuthAction
authOAuth1() Performs OAuth1 auth flow. yii\authclient\AuthAction
authOAuth2() Performs OAuth2 auth flow. yii\authclient\AuthAction
authOpenId() Performs OpenID auth flow. yii\authclient\AuthAction
authSuccess() This method is invoked in case of successful authentication via auth client. yii\authclient\AuthAction
beforeRun() This method is called right before run() is executed. yii\base\Action
defaultCancelUrl() Creates default $cancelUrl value. yii\authclient\AuthAction
defaultSuccessUrl() Creates default $successUrl value. yii\authclient\AuthAction

Property Details

$cancelUrl public property

Cancel URL.

public string getCancelUrl ( )
public void setCancelUrl ( $url )

$clientCollection public property

Name of the auth client collection application component. It should point to yii\authclient\Collection instance.

public string $clientCollection = 'authClientCollection'

$clientIdGetParamName public property

Name of the GET param, which is used to passed auth client id to this action. Note: watch for the naming, make sure you do not choose name used in some auth protocol.

public string $clientIdGetParamName = 'authclient'

$redirectView public property

Name or alias of the view file, which should be rendered in order to perform redirection. If not set - default one will be used.

public string $redirectView = null

$successCallback public property

PHP callback, which should be triggered in case of successful authentication. This callback should accept yii\authclient\ClientInterface instance as an argument. For example:

public function onAuthSuccess($client)
{
    $attributes = $client->getUserAttributes();
    // user login or signup comes here
}

If this callback returns yii\web\Response instance, it will be used as action response, otherwise redirection to $successUrl will be performed.

public callable $successCallback = null

$successUrl public property

Successful URL.

public string getSuccessUrl ( )
public void setSuccessUrl ( $url )

Method Details

auth() protected method

Perform authentication for the given client.

protected yii\web\Response auth ( $client )
$client mixed

Auth client instance.

return yii\web\Response

Response instance.

throws yii\base\NotSupportedException

on invalid client.

authOAuth1() protected method

Performs OAuth1 auth flow.

protected yii\web\Response authOAuth1 ( $client )
$client yii\authclient\OAuth1

Auth client instance.

return yii\web\Response

Action response.

authOAuth2() protected method

Performs OAuth2 auth flow.

protected yii\web\Response authOAuth2 ( $client )
$client yii\authclient\OAuth2

Auth client instance.

return yii\web\Response

Action response.

throws yii\base\Exception

on failure.

authOpenId() protected method

Performs OpenID auth flow.

protected yii\web\Response authOpenId ( $client )
$client yii\authclient\OpenId

Auth client instance.

return yii\web\Response

Action response.

throws yii\base\Exception

on failure.

throws yii\web\HttpException

on failure.

authSuccess() protected method

This method is invoked in case of successful authentication via auth client.

protected yii\web\Response authSuccess ( $client )
$client yii\authclient\ClientInterface

Auth client instance.

return yii\web\Response

Response instance.

throws yii\base\InvalidConfigException

on invalid success callback.

defaultCancelUrl() protected method

Creates default $cancelUrl value.

protected string defaultCancelUrl ( )
return string

Cancel URL value.

defaultSuccessUrl() protected method

Creates default $successUrl value.

protected string defaultSuccessUrl ( )
return string

Success URL value.

getCancelUrl() public method

public string getCancelUrl ( )
return string

Cancel URL.

getSuccessUrl() public method

public string getSuccessUrl ( )
return string

Successful URL.

redirect() public method

Redirect to the given URL or simply close the popup window.

public yii\web\Response redirect ( $url, $enforceRedirect = true )
$url mixed

URL to redirect, could be a string or array config to generate a valid URL.

$enforceRedirect boolean

Indicates if redirect should be performed even in case of popup window.

return yii\web\Response

Response instance.

redirectCancel() public method

Redirect to the $cancelUrl or simply close the popup window.

public yii\web\Response redirectCancel ( $url = null )
$url string

URL to redirect.

return yii\web\Response

Response instance.

redirectSuccess() public method

Redirect to the URL. If URL is null, $successUrl will be used.

public yii\web\Response redirectSuccess ( $url = null )
$url string

URL to redirect.

return yii\web\Response

Response instance.

run() public method

Runs the action.

public void run ( )

setCancelUrl() public method

public void setCancelUrl ( $url )
$url string

Cancel URL.

setSuccessUrl() public method

public void setSuccessUrl ( $url )
$url string

Successful URL.

© 2008–2017 by Yii Software LLC
Licensed under the three clause BSD license.
http://www.yiiframework.com/doc-2.0/yii-authclient-authaction.html