Class yii\authclient\AuthAction
Inheritance | yii\authclient\AuthAction » yii\base\Action |
---|---|
Available since version | 2.0 |
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 |
---|---|---|---|
$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 |
$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 |
Public Methods
Method | Description | Defined By |
---|---|---|
getCancelUrl() | yii\authclient\AuthAction | |
getSuccessUrl() | yii\authclient\AuthAction | |
redirect() | Redirect to the given URL or simply close the popup window. | yii\authclient\AuthAction |
redirectCancel() | Redirect to the \yii\authclient\cancelUrl or simply close the popup window. | yii\authclient\AuthAction |
redirectSuccess() | Redirect to the URL. If URL is null, \yii\authclient\successUrl will be used. | yii\authclient\AuthAction |
run() | Runs the action. | yii\authclient\AuthAction |
setCancelUrl() | yii\authclient\AuthAction | |
setSuccessUrl() | yii\authclient\AuthAction |
Protected Methods
Method | Description | Defined By |
---|---|---|
auth() | 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 |
defaultCancelUrl() | Creates default \yii\authclient\cancelUrl value. | yii\authclient\AuthAction |
defaultSuccessUrl() | Creates default \yii\authclient\successUrl value. | yii\authclient\AuthAction |
Property Details
Name of the auth client collection application component. It should point to yii\authclient\Collection instance.
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.
Name or alias of the view file, which should be rendered in order to perform redirection. If not set default one will be used.
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 \yii\authclient\successUrl will be performed.
Method Details
protected \yii\web\Response auth ( $client ) | ||
$client | mixed | Auth client instance. |
return | \yii\web\Response | Response instance. |
---|---|---|
throws | \yii\base\NotSupportedException | on invalid client. |
Performs OAuth1 auth flow.
protected \yii\web\Response authOAuth1 ( $client ) | ||
$client | yii\authclient\OAuth1 | Auth client instance. |
return | \yii\web\Response | Action response. |
---|
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. |
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. |
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. |
Creates default \yii\authclient\cancelUrl value.
protected string defaultCancelUrl ( ) | ||
return | string | Cancel URL value. |
---|
Creates default \yii\authclient\successUrl value.
protected string defaultSuccessUrl ( ) | ||
return | string | Success URL value. |
---|
public string getCancelUrl ( ) | ||
return | string | Cancel URL. |
---|
public string getSuccessUrl ( ) | ||
return | string | Successful URL. |
---|
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. |
---|
Redirect to the \yii\authclient\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. |
---|
Redirect to the URL. If URL is null, \yii\authclient\successUrl will be used.
public \yii\web\Response redirectSuccess ( $url = null ) | ||
$url | string | URL to redirect. |
return | \yii\web\Response | Response instance. |
---|
Runs the action.
public void run ( ) |
public void setCancelUrl ( $url ) | ||
$url | string | Cancel URL. |
public void setSuccessUrl ( $url ) | ||
$url | string | Successful URL. |