This extension implements HybridAuth to enable social logins (Facebook, Yahoo etc) for Yii.
The first time someone passes the authentication with their provider, they are prompted to choose a username and optionally an email address (the email address isn't verified).
It extends CBaseUserIdentity to RemoteUserIdentity and so can be used in parallel to the default Yii login that comes with the skeleton app. In fact it is intended to be used that way. It can also be used with yii-user.
if someone is already logged in, and clicks another provider it will associate that provider with the users website account as well, so multiple providers can be linked to one account. Clicking a linked provider (with a green background) will unlink that provider from the account.
This has been written against the skeleton application generated by Yii. It assumes you have a User model & corresponding database table.
For most providers you will need to register with them for an API key. One exception to this is Yahoo.
Unzip into protected\modules\
Add the following to the "modules" section in main.php:
'hybridauth' => array( 'baseUrl' => 'http://'. $_SERVER['SERVER_NAME'] . '/hybridauth', 'withYiiUser' => false, // Set to true if using yii-user "providers" => array ( "openid" => array ( "enabled" => true ), "yahoo" => array ( "enabled" => true ), "google" => array ( "enabled" => true, "keys" => array ( "id" => "", "secret" => "" ), "scope" => "" ), "facebook" => array ( "enabled" => true, "keys" => array ( "id" => "", "secret" => "" ), "scope" => "email,publish_stream", "display" => "" ), "twitter" => array ( "enabled" => true, "keys" => array ( "key" => "", "secret" => "" ) ) ) ),
Run the following SQL to create the table to hold the logins.
CREATE TABLE IF NOT EXISTS `ha_logins` ( `id` int(11) NOT NULL AUTO_INCREMENT, `userId` int(11) NOT NULL, `loginProvider` varchar(50) NOT NULL, `loginProviderIdentifier` varchar(100) NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `loginProvider_2` (`loginProvider`,`loginProviderIdentifier`), KEY `loginProvider` (`loginProvider`), KEY `loginProviderIdentifier` (`loginProviderIdentifier`), KEY `userId` (`userId`), KEY `id` (`id`) ) ENGINE=InnoDB
You can either then just link people directly to the URL '/hybridauth' to login, or add a widget to another view:
$this->widget('application.modules.hybridauth.widgets.renderProviders');
In your controllers you can then get the Hybrid_Auth object:
$ha = Yii::app()->getModule('hybridauth')->getHybridAuth(); $facebook = $ha->getAdapter('facebook'); $facebook->setUserStatus('Hi');
See the Hybrid_Auth docs for more details.
At the moment it swallows exceptions generated by the providers, and displays the user a generic "something has gone wrong" message. If you are having problems working out what is going wrong, and want to show exceptions, then comment out the try..catch lines in function DefaultController::actionLogin() so the exceptions don't get caught and instead will halt the app.
Forum thread - http://www.yiiframework.com/forum/index.php/topic/33309-module-hybridauth/
Total 10 comments
Thanks for this nice work. There is also an independent implementation of hybrid auth integrated into yii user management >= 0.9:
https://github.com/thyseus/yii-user-management
class DefaultController extends CController, not Controller..
How improt contact of user using hybrid auth for provider google , live and yahoo.
I had searched more but i didn't find any solution.
Is it possible or not. I looked Yahoo.php which has no methods for importing contact.
Can anyone done this type work before using this library. or not .
Thank you waiting for you response.
I am getting used to this nice extension, but I have incorporated hybridauth with yii-user and I cannot figure out how to update the lastvisit_at field. It just remains at the default 0000-00-00 00:00:00 in my database table.
Any suggestions?
Hi,
Linkedin provider API has changed a bit, so now it can fetch the verified email address, when compared to the existing provider inside ext. you need to replace with the new one please
thank you very much, Happy new year !
Nice module and really saved lots of time for us.. however, I'm faced with an issue here and im not sure if all have the same thing:
Any help please
Regards, Basem
Thx for great module. I manage to make it works without any problems. So far I tested google, twitter, facebook. You can try it here: milosnicyzwierzat.pl. I had problem with yahoo login, I got informed that CSRF token could not be verified. I've seen this problem already on the forum, but no one has solution.
Regards and txh for great job again lukBB
I had integrated hybridauth in http://www.carbonbuster.org with social media login. I can login with social meida login. When I want to share with those loged in social media's that I had integrated than I got error as
Fatal error: Class 'CExceptionEvent' not found in /home/carbon/domains/carbonbuster.org/public_html/framework/base/CApplication.php on line 707
so I don't know how to fix this problem. I am expecting help from all those who can help.
Just a note I have version 1.2 installed and when I was trying it I got require_once example google.php for the list of providers error and after changing the module configuration in main from google to Google the error disappeared case sensitive issues. before
After
I was able to login with yahoo But coming back to my page am getting The CSRF token could not be verified. I have cookies enable any idea how to fix this.
Yii HybridAuth Extension: https://github.com/markvr/hybridauth
PHP HybridAuth Library: https://github.com/hybridauth/hybridauth
Leave a comment
Please login to leave your comment.