appage/yii2-authclient

Auth client for appage projects

This package's canonical repository appears to be gone and the package has been frozen as a result.

Installs: 46

Dependents: 0

Suggesters: 0

Security: 0

Type:yii2-extension

v0.1.3 2017-09-20 20:47 UTC

This package is auto-updated.

Last update: 2019-05-26 00:51:07 UTC


README

Auth client for appage projects

Installation

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"

Usage

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,
    ]) ?>