Auth client for appage projects
Auth client for appage projects
The preferred way to install this extension is through composer.
Either run
composer require --prefer-dist appage/yii2-authclient "*"
or add
"appage/yii2-authclient": "*"
to the require section of your composer.json
file.
Then start migration:
php yii migrate --migrationNamespaces="appage\authclient\migrations"
SiteController:
public function actions()
{
return [
...
'auth' => [
'class' => 'yii\authclient\AuthAction',
'successCallback' => [$this, 'onAuthSuccess'],
],
...
];
}
public function onAuthSuccess($client)
{
(new AuthHandler($client))->handle();
}
You can add next params to main.php:
return [
'components' => [
'authClientCollection' => [
'class' => 'yii\authclient\Collection',
'clients' => [
'google' => [
'class' => 'yii\authclient\clients\Google',
'clientId' => 'google_client_id',
'clientSecret' => 'google_client_secret',
],
'facebook' => [
'class' => 'yii\authclient\clients\Facebook',
'clientId' => 'facebook_client_id',
'clientSecret' => 'facebook_client_secret',
],
// etc.
],
],
// ...
],
// ...
];
Then you can add Auth widget to login.php
<?= yii\authclient\widgets\AuthChoice::widget([
'baseAuthUrl' => ['site/auth'],
'popupMode' => false,
]) ?>