PHP Класс yii\authclient\AuthAction

It supports OpenId, OAuth1 and OAuth2 client types. Usage: php 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.
См. также: Collection
См. также: yii\authclient\widgets\AuthChoice
С версии: 2.0
Автор: Paul Klimov ([email protected])
Наследование: extends yii\base\Action
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$clientCollection name of the auth client collection application component. It should point to Collection instance.
$clientIdGetParamName 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.
$redirectView name or alias of the view file, which should be rendered in order to perform redirection. If not set - default one will be used.
$successCallback PHP callback, which should be triggered in case of successful authentication. This callback should accept [[ClientInterface]] instance as an argument. For example: php public function onAuthSuccess($client) { $attributes = $client->getUserAttributes(); user login or signup comes here } If this callback returns [[Response]] instance, it will be used as action response, otherwise redirection to [[successUrl]] will be performed.

Открытые методы

Метод Описание
getCancelUrl ( ) : string
getSuccessUrl ( ) : string
redirect ( mixed $url, boolean $enforceRedirect = true ) : Response Redirect to the given URL or simply close the popup window.
redirectCancel ( string $url = null ) : Response Redirect to the [[cancelUrl]] or simply close the popup window.
redirectSuccess ( string $url = null ) : Response Redirect to the URL. If URL is null, [[successUrl]] will be used.
run ( ) Runs the action.
setCancelUrl ( string $url )
setSuccessUrl ( string $url )

Защищенные методы

Метод Описание
auth ( mixed $client ) : Response Perform authentication for the given client.
authOAuth1 ( OAuth1 $client ) : Response Performs OAuth1 auth flow.
authOAuth2 ( OAuth2 $client ) : Response Performs OAuth2 auth flow.
authOpenId ( OpenId $client ) : Response Performs OpenID auth flow.
authSuccess ( yii\authclient\ClientInterface $client ) : Response This method is invoked in case of successful authentication via auth client.
defaultCancelUrl ( ) : string Creates default [[cancelUrl]] value.
defaultSuccessUrl ( ) : string Creates default [[successUrl]] value.

Описание методов

auth() защищенный метод

Perform authentication for the given client.
protected auth ( mixed $client ) : Response
$client mixed auth client instance.
Результат yii\web\Response response instance.

authOAuth1() защищенный метод

Performs OAuth1 auth flow.
protected authOAuth1 ( OAuth1 $client ) : Response
$client OAuth1 auth client instance.
Результат yii\web\Response action response.

authOAuth2() защищенный метод

Performs OAuth2 auth flow.
protected authOAuth2 ( OAuth2 $client ) : Response
$client OAuth2 auth client instance.
Результат yii\web\Response action response.

authOpenId() защищенный метод

Performs OpenID auth flow.
protected authOpenId ( OpenId $client ) : Response
$client OpenId auth client instance.
Результат yii\web\Response action response.

authSuccess() защищенный метод

This method is invoked in case of successful authentication via auth client.
protected authSuccess ( yii\authclient\ClientInterface $client ) : Response
$client yii\authclient\ClientInterface auth client instance.
Результат yii\web\Response response instance.

defaultCancelUrl() защищенный метод

Creates default [[cancelUrl]] value.
protected defaultCancelUrl ( ) : string
Результат string cancel URL value.

defaultSuccessUrl() защищенный метод

Creates default [[successUrl]] value.
protected defaultSuccessUrl ( ) : string
Результат string success URL value.

getCancelUrl() публичный метод

public getCancelUrl ( ) : string
Результат string cancel URL.

getSuccessUrl() публичный метод

public getSuccessUrl ( ) : string
Результат string successful URL.

redirect() публичный метод

Redirect to the given URL or simply close the popup window.
public redirect ( mixed $url, boolean $enforceRedirect = true ) : Response
$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.
Результат yii\web\Response response instance.

redirectCancel() публичный метод

Redirect to the [[cancelUrl]] or simply close the popup window.
public redirectCancel ( string $url = null ) : Response
$url string URL to redirect.
Результат yii\web\Response response instance.

redirectSuccess() публичный метод

Redirect to the URL. If URL is null, [[successUrl]] will be used.
public redirectSuccess ( string $url = null ) : Response
$url string URL to redirect.
Результат yii\web\Response response instance.

run() публичный метод

Runs the action.
public run ( )

setCancelUrl() публичный метод

public setCancelUrl ( string $url )
$url string cancel URL.

setSuccessUrl() публичный метод

public setSuccessUrl ( string $url )
$url string successful URL.

Описание свойств

$clientCollection публичное свойство

name of the auth client collection application component. It should point to Collection instance.
public $clientCollection

$clientIdGetParamName публичное свойство

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 $clientIdGetParamName

$redirectView публичное свойство

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 $redirectView

$successCallback публичное свойство

PHP callback, which should be triggered in case of successful authentication. This callback should accept [[ClientInterface]] instance as an argument. For example: php public function onAuthSuccess($client) { $attributes = $client->getUserAttributes(); user login or signup comes here } If this callback returns [[Response]] instance, it will be used as action response, otherwise redirection to [[successUrl]] will be performed.
public $successCallback