PHP Class 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.
See also: Collection
See also: yii\authclient\widgets\AuthChoice
Since: 2.0
Author: Paul Klimov (klimov.paul@gmail.com)
Inheritance: extends yii\base\Action
Datei anzeigen Open project: yiisoft/yii2-authclient Class Usage Examples

Public Properties

Property Type Description
$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.

Public Methods

Method Description
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 )

Protected Methods

Method Description
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.

Method Details

auth() protected method

Perform authentication for the given client.
protected auth ( mixed $client ) : Response
$client mixed auth client instance.
return yii\web\Response response instance.

authOAuth1() protected method

Performs OAuth1 auth flow.
protected authOAuth1 ( OAuth1 $client ) : Response
$client OAuth1 auth client instance.
return yii\web\Response action response.

authOAuth2() protected method

Performs OAuth2 auth flow.
protected authOAuth2 ( OAuth2 $client ) : Response
$client OAuth2 auth client instance.
return yii\web\Response action response.

authOpenId() protected method

Performs OpenID auth flow.
protected authOpenId ( OpenId $client ) : Response
$client OpenId auth client instance.
return yii\web\Response action response.

authSuccess() protected method

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.
return yii\web\Response response instance.

defaultCancelUrl() protected method

Creates default [[cancelUrl]] value.
protected defaultCancelUrl ( ) : string
return string cancel URL value.

defaultSuccessUrl() protected method

Creates default [[successUrl]] value.
protected defaultSuccessUrl ( ) : string
return string success URL value.

getCancelUrl() public method

public getCancelUrl ( ) : string
return string cancel URL.

getSuccessUrl() public method

public getSuccessUrl ( ) : string
return string successful URL.

redirect() public method

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.
return yii\web\Response response instance.

redirectCancel() public method

Redirect to the [[cancelUrl]] or simply close the popup window.
public redirectCancel ( string $url = null ) : Response
$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 redirectSuccess ( string $url = null ) : Response
$url string URL to redirect.
return yii\web\Response response instance.

run() public method

Runs the action.
public run ( )

setCancelUrl() public method

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

setSuccessUrl() public method

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

Property Details

$clientCollection public_oe property

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

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

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

$successCallback public_oe property

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