Skip to content

Latest commit

 

History

History
143 lines (114 loc) · 3.89 KB

social-auth.md

File metadata and controls

143 lines (114 loc) · 3.89 KB

Authentication via social networks

Yii2-user provides user registration and login using social sites credentials. It also allows to connect multiple social networks to user account and use them to log in.

Getting started

To get started you should configure authClientCollection application component:

...
'components' => [
    ...
    'authClientCollection' => [
        'class'   => \yii\authclient\Collection::className(),
        'clients' => [
            // here is the list of clients you want to use
            // you can read more in the "Available clients" section
        ],
    ],
    ...
],
...

Available clients

Here is the list of clients supported by the module:

Facebook

  • You can register new application and get secret keys here.
'facebook' => [
    'class'        => 'dektrium\user\clients\Facebook',
    'clientId'     => 'APP_ID',
    'clientSecret' => 'APP_SECRET',
],

Twitter

  • You can register new application and get secret keys here.

NOTE: Current version of Twitter API does not provide user's email address, so we can't register user without making him enter his email address

'twitter' => [
    'class'          => 'dektrium\user\clients\Twitter',
    'consumerKey'    => 'CONSUMER_KEY',
    'consumerSecret' => 'CONSUMER_SECRET',
],

Google

  • You can register new application and get secret keys here.
  • First of all you need to enable Google+ API in APIs & auth section.
  • Then you need to create new client id on APIs & auth > Credentials section
  • Authorized JavaScript origins should contain url like http://localhost
  • Authorized redirect URIs should contain url like http://localhost/user/security/auth?authclient=google
'google' => [
    'class'        => 'dektrium\user\clients\Google',
    'clientId'     => 'CLIENT_ID',
    'clientSecret' => 'CLIENT_SECRET',
],

Github

  • You can register new application and get secret keys here.
'github' => [
    'class'        => 'dektrium\user\clients\GitHub',
    'clientId'     => 'CLIENT_ID',
    'clientSecret' => 'CLIENT_SECRET',
],

VKontakte

  • You can register new application and get secret keys here.
'vkontakte' => [
    'class'        => 'dektrium\user\clients\VKontakte',
    'clientId'     => 'CLIENT_ID',
    'clientSecret' => 'CLIENT_SECRET',
]

Yandex

  • You can register new application and get secret keys here.
  • Make sure that you have enabled access to email address in Yandex.Passport API section.
  • Also you should set the callback url to url like http://localhost/user/security/auth?authclient=yandex.
'yandex' => [
    'class'        => 'dektrium\user\clients\Yandex',
    'clientId'     => 'CLIENT_ID',
    'clientSecret' => 'CLIENT_SECRET'
],

Configuration example

The following config allows to log in using 3 networks (Twitter, Facebook and Google):

'authClientCollection' => [
    'class' => yii\authclient\Collection::className(),
    'clients' => [
        'facebook' => [
            'class'        => 'dektrium\user\clients\Facebook',
            'clientId'     => 'CLIENT_ID',
            'clientSecret' => 'CLIENT_SECRET',
        ],
        'twitter' => [
            'class'          => 'dektrium\user\clients\Twitter',
            'consumerKey'    => 'CONSUMER_KEY',
            'consumerSecret' => 'CONSUMER_SECRET',
        ],
        'google' => [
            'class'        => 'dektrium\user\clients\Google',
            'clientId'     => 'CLIENT_ID',
            'clientSecret' => 'CLIENT_SECRET',
        ],
    ],
],