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.
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
],
],
...
],
...
Here is the list of clients supported by the module:
- You can register new application and get secret keys here.
'facebook' => [
'class' => 'dektrium\user\clients\Facebook',
'clientId' => 'APP_ID',
'clientSecret' => 'APP_SECRET',
],
- 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',
],
- 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 likehttp://localhost
Authorized redirect URIs
should contain url likehttp://localhost/user/security/auth?authclient=google
'google' => [
'class' => 'dektrium\user\clients\Google',
'clientId' => 'CLIENT_ID',
'clientSecret' => 'CLIENT_SECRET',
],
- You can register new application and get secret keys here.
'github' => [
'class' => 'dektrium\user\clients\GitHub',
'clientId' => 'CLIENT_ID',
'clientSecret' => 'CLIENT_SECRET',
],
- You can register new application and get secret keys here.
'vkontakte' => [
'class' => 'dektrium\user\clients\VKontakte',
'clientId' => 'CLIENT_ID',
'clientSecret' => 'CLIENT_SECRET',
]
- 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'
],
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',
],
],
],