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.
Requirements ¶
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.
Installation ¶
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
Usage ¶
You can either then just link people directly to the URL '/hybridauth' to login, or add a widget to another view:
<?php $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.
Notes ¶
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.
Resources ¶
Forum thread - http://www.yiiframework.com/forum/index.php/topic/33309-module-hybridauth/
The code is on github here:
Yii HybridAuth Extension:
https://github.com/markvr/hybridauth
PHP HybridAuth Library:
https://github.com/hybridauth/hybridauth
Nice module
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
'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" => "" ) ) ) ),
After
'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" => "" ) ) ) ),
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.
Hi I am having problem with sharing with hybridauth
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.
great module
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
One problem
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
Linkedin provider has changed a bit
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 !
User lastvisit_at
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?
I want to import contact list of user
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.
DefaultController.php
class DefaultController extends CController, not Controller..
Nice work! Hybridauth for yii-user-management is also available now!
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
Thanks for extension!
Hi! thanks for this extension. First I've tried another but this worked faster for me and not too complicated.
But there was small workaround needed because I have PostgreSQL and I had to change table script and change column names to lowercase. After that I get it worked.
If you want searching how to upgrade your extension this would be one of the directions :)
Thanks again!
EDIT: I could not make it lowercase, but just write column names in quotes
~~~
[sql]
CREATE TABLE ha_logins (
id serial NOT NULL, "loginProvider" character varying(50) NOT NULL, "loginProviderIdentifier" character varying(102) NOT NULL, "userId" integer NOT NULL, CONSTRAINT ha_logins_pkey PRIMARY KEY (id), FOREIGN KEY("userId") REFERENCES "user" (id)
);
~~~
But anyway there was problem on HaLogin.php with all "$criteria->compare(" because I need to put every column in quotes there too.
Problem after login
When I did my login, i got the following error:
include(DefaultController.php): failed to open stream: No such file or directory
protected\modules\hybridauth\Hybrid\Storage.php(26): unserialize("O:9:"Exception":7:{s:10:"*message";s:63:"Authentification fail...")
protected\modules\hybridauth\Hybrid\Auth.php(143): Hybrid_Error::getErrorPrevious()
.......
Any ideas why this happens?
Muito bom!!
Implementei essa extensão no meu projeto e fico muito bom... funciona mesmo!
Deprecated Twitter api (v. 1.0)
Twitter updated their api and deprecated the 1.0 version since July 2013, so in order to have a working twitter oAuth you need to download the latest hybridAuth library from http://hybridauth.sourceforge.net/. Then replace Twitter.php from the Providers folder into yii module and twitter integration will work again.
Can I need to put 'hybridauth' library in my localhsot root?
Can I need to put 'hybridauth' library in my localhsot root?
As your code in config pointout this:
'hybridauth' => array( 'baseUrl' => 'http://'. $_SERVER['SERVER_NAME'] . '/hybridauth',
when I echo this baseUrl,I saw this Url:
http://localhost/hybridauth
and I'm getting this error when I tried to connect with Facebook:
User not connected to the provider Facebook.
I'm logged in my fb account also I gave id and secret in config.
GREAT!
the easiest to implement by far! took all but 5 minutes - the other ones had me stuck for days! Thanks!!
DefaultController not found
Just like Maurice_ I too have the problem that I get the error message: include(DefaultController.php) [function.include]: failed to open stream: No such file or directory
I have \protected\modules\hybridauth\controllers\DefaultController.php
What can I do?
It happends when I have logged in with hybridauth. When I am not logged in or have logged out I can locate defautcontroller with address hybridauth/default/
I need the profile details of user after authentication
I need the profile details of user after authentication via hybrid auth
how can I get in defaultcontroller and save to my custom database table.
I am planing to get the profile details and autoregister with that details.
How can I do that any suggestions ?
Google login not work when url is without www
Hi All,
I have a website with this module. I set the redirect url in my google settings starting with www. If the url is without the www, the webpage shows but trying to login with google will give a redirect url error.
Is there a way to set hybridauth to always append www when a request url does not include it?
Thanks
I also faced this error
Hi I also faced this error but I asked my host provider to do that
carbonbuster.org you can check this. So you don't face any problem hope you can consult your host provider in doing so
i appreciate your help
Hi nirmalroka,
Thank you for your suggestion. I tried it and it worked. However, it created another issue since i tried to hide index.php in my htaccess file.
The controller id was constantly being replaced by index.php
I set the url of the login button manually, including www for google. This solved the problem. It means if the domain name changes,i'd have to edit this again.
Got blank page in server.
Hi,
I got blank page in server,its working in localhost fine but not working in server why?
Try to log the obect you are gettin
Try to log the hybridauth object so that you can know what happening, double check the url of the site, hybrid config
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.