EAuth extension allows to authenticate users with accounts on other websites. Supported protocols: OpenID, OAuth 1.0 and OAuth 2.0.
EAuth is a extension for provide a unified (does not depend on the selected service) method to authenticate the user. So, the extension itself does not perform login, does not register the user and does not bind the user accounts from different providers.
The implementation of the authorization on your own server has several advantages:
protected/extensions
protected/config/main.php
, add the following:```php <?php ... 'import'=>array( 'ext.eoauth.*', 'ext.eoauth.lib.*', 'ext.lightopenid.*', 'ext.eauth.*', 'ext.eauth.services.*', ), ... 'components'=>array( 'loid' => array( 'class' => 'ext.lightopenid.loid', ), 'eauth' => array( 'class' => 'ext.eauth.EAuth', 'popup' => true, // Use the popup window instead of redirecting. 'services' => array( // You can change the providers and their classes. 'google' => array( 'class' => 'GoogleOpenIDService', ), 'yandex' => array( 'class' => 'YandexOpenIDService', ), 'twitter' => array( // register your app here: https://dev.twitter.com/apps/new 'class' => 'TwitterOAuthService', 'key' => '...', 'secret' => '...', ), 'google_oauth' => array( // register your app here: https://code.google.com/apis/console/ 'class' => 'GoogleOAuthService', 'client_id' => '...', 'client_secret' => '...', 'title' => 'Google (OAuth)', ), 'facebook' => array( // register your app here: https://developers.facebook.com/apps/ 'class' => 'FacebookOAuthService', 'client_id' => '...', 'client_secret' => '...', ), 'vkontakte' => array( // register your app here: http://vkontakte.ru/editapp?act=create&site=1 'class' => 'VKontakteOAuthService', 'client_id' => '...', 'client_secret' => '...', ), 'mailru' => array( // register your app here: http://api.mail.ru/sites/my/add 'class' => 'MailruOAuthService', 'client_id' => '...', 'client_secret' => '...', ), 'moikrug' => array( // register your app here: https://oauth.yandex.ru/client/my 'class' => 'MoikrugOAuthService', 'client_id' => '...', 'client_secret' => '...', ), 'odnoklassniki' => array( // register your app here: http://www.odnoklassniki.ru/dk?st.cmd=appsInfoMyDevList&st._aid=Apps_Info_MyDev 'class' => 'OdnoklassnikiOAuthService', 'client_id' => '...', 'client_public' => '...', 'client_secret' => '...', 'title' => 'Odnokl.', ), ), ), ... ), ... ```
```php <?php ... public function actionLogin() { $service = Yii::app()->request->getQuery('service'); if (isset($service)) { $authIdentity = Yii::app()->eauth->getIdentity($service); $authIdentity->redirectUrl = Yii::app()->user->returnUrl; $authIdentity->cancelUrl = $this->createAbsoluteUrl('site/login');
if ($authIdentity->authenticate()) { $identity = new EAuthUserIdentity($authIdentity);
// successful authentication if ($identity->authenticate()) { Yii::app()->user->login($identity);
// special redirect with closing popup window $authIdentity->redirect(); } else { // close popup window and redirect to cancelUrl $authIdentity->cancel(); } }
// Something went wrong, redirect to login page $this->redirect(array('site/login')); }
// default authorization code through login/password .. } ```
```php
<?php $this->widget('ext.eauth.EAuthWidget', array('action' => 'site/login')); ?> ```
To receive all the necessary data to your application, you can override the base class of any provider. Base classes are stored in protected/extensions/eauth/services/
. Examples of extended classes can be found in protected/extensions/eauth/custom_services/
.
After overriding the base class, you need to modify your configuration file to set new name of the class. Also you may need to override the EAuthUserIdentity
class to store additional data.
/protected/extensions/eauth/messages/[lang]/eauth.php
to /protected/messages/[lang]/eauth.php
to translate the EAuth extension into other languages./protected/extensions/eauth/messages/blank/eauth.php
.Some time ago I developed this extension for LiStick.ru and I still support the extension.
The extension was released under the New BSD License, so you'll find the latest version on GitHub.