[MODULE] HybridAuth

example config:


'modules'=>array(

		'hybridauth' => array(

			'baseUrl' => 'http://'. $_SERVER['SERVER_NAME'] . '/hybridauth', 

			'withYiiUser' => false,

			"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" => "" ),


					// A comma-separated list of permissions you want to request from the user. See the Facebook docs for a full list of available permissions: http://developers.facebook.com/docs/reference/api/permissions.

					"scope"   => "email", 


					// The display context to show the authentication page. Options are: page, popup, iframe, touch and wap. Read the Facebook docs for more details: http://developers.facebook.com/docs/reference/dialogs#display. Default: page

					"display" => "" 

				),


				"twitter" => array ( 

					"enabled" => true,

					"keys"    => array ( "key" => "", "secret" => "" ) 

				)

			)

		),

A quick question - does this extension allow a single user to link multiple 3rd party providers to their account? Or are they forced to choose just one provider? Based on the page in the extensions directory, the table modification forces a user to have just one provider.

The ability to link multiple providers to a single user was one of the strengths of the Yii-auth implementation. Sampa did a great job, but the approach was messy. If this extension has multiple providers per user, then it will meet my requirements.

You know, you can ignore that. I just refreshed the source page on github and see you have added a separate table - thus resolving the issue. Thanks.

Hi there,

Thanks for the feature for Yii User. I now get another error:




PHP warning


include(HaLogins.php): failed to open stream: No such file or directory


/home/something/yii/framework/YiiBase.php(418)


406                 {

407                     foreach(self::$_includePaths as $path)

408                     {

409                         $classFile=$path.DIRECTORY_SEPARATOR.$className.'.php';

410                         if(is_file($classFile))

411                         {

412                             include($classFile);

413                             break;

414                         }

415                     }

416                 }

417                 else

418                     include($className.'.php');

419             }

420             else  // class name with namespace in PHP 5.3

421             {

422                 $namespace=str_replace('\\','.',ltrim($className,'\\'));

423                 if(($path=self::getPathOfAlias($namespace))!==false)

424                     include($path.'.php');

425                 else

426                     return false;

427             }

428             return class_exists($className,false) || interface_exists($className,false);

429         }

430         return true;


Stack Trace

#0 	

+

 /home/something/yii/framework/YiiBase.php(418): YiiBase::autoload()

#1 	

 unknown(0): YiiBase::autoload("HaLogins")

#2 	

+

 /home/something/yii/framework/db/ar/CActiveRecord.php(378): spl_autoload_call("HaLogins")

#3 	

+

 /home/something/yii/framework/web/CActiveDataProvider.php(75): CActiveRecord::model("HaLogins")

#4 	

–

 /home/something/protected/modules/hybridauth/models/HaLogin.php(104): CActiveDataProvider->__construct("HaLogins", array("criteria" => CDbCriteria))


099         $criteria->compare('loginProvider',$loginProvider,true);

100         $criteria->compare('loginProviderIdentifier',$loginProviderIdentity,true);

101 

102         $login = new CActiveDataProvider('HaLogins', array(

103             'criteria'=>$criteria,

104         ));

105         

106         if ($login->itemCount == 0) {

107             return null;

108         } else {

109             // TODO - Can't seem to get this to work with relations properly....


#5 	

–

 /home/something/protected/modules/hybridauth/components/RemoteUserIdentity.php(43): HaLogin::getUser("Yahoo", "censored-url")


38         $adapter = $hybridauth->authenticate($this->loginProvider,$params);

39         if ($adapter->isUserConnected()) {

40             $this->_adapter = $adapter;

41             $this->loginProviderIdentifier = $this->_adapter->getUserProfile()->identifier;

42 

43             $user = HaLogin::getUser($this->loginProvider, $this->loginProviderIdentifier);

44             

45             if ($user == null) {

46                 $this->errorCode = self::ERROR_USERNAME_INVALID;

47             } else {

48                 $this->id = $user->id;


#6 	

–

 /home/something/protected/modules/hybridauth/controllers/DefaultController.php(44): RemoteUserIdentity->authenticate()


39         }

40         

41 

42         $identity = new RemoteUserIdentity($_GET['provider']);

43         

44         if ($identity->authenticate()) {

45             // They have authenticated AND we have a user record associated with that provider

46             if (Yii::app()->user->isGuest) {

47                 $this->_loginUser($identity);

48             } else {

49                 //they shouldn't get here because they are already logged in AND have a record for




If you need more informations, I will be happy to provide them.

Thanks again!

Kudos for putting it up on Github! :)

HaLogin should be singular not plural, I wonder if the lines like




$login = new CActiveDataProvider('HaLogins', array(

			'criteria'=>$criteria,

		));



are wrong, but if so it wouldn’t work at all, but it does work on my PC. Hmm, I might have some old detrius lying around that made it work on my PC but no one elses! This is why I haven’t updated the Yii repo extension, what’s on Github isn’t properly tested yet.

I’ll take a look and let you know.

cheers,

mark

Removing the S from HaLogins fixed it, thanks again!

The only thing bugging me now is getting the error message from the provider instead of:


 User profile request failed! Google returned an invalide response. 

Also, I have remove the strings firstname and lastname from the DefaultController, but that’s just me.

Yep, I had an old HaLogins model floating around which meant it worked on my PC. Fixed and updated Github

Don’t know, I haven’t tested with Google, there’s only so many providers I can test with! Might be worth checking the HybridAuth docs on sourceforge.

Yeah that’s a bit of a bodge but Yii User needs those entries filled in otherwise it bombs out when you view the profile. A better solution is going to be to fork the view that requests a username/email to include names as well if it’s running in Yii User.

Updated the extension with multiple providers, and you can now also get the Hybrid_Auth class to write statuses to facebook etc.

See the extension for details.

I’m curious if the RemoteUserIdentity property userData is just a general idea or if it’s fully implemented yet.

This seemed to make the most sense to me…

protected.modules.hybridauth.components.RemoteUserIdentity line 41 (function authenticate)


            $this->userData = $this->_adapter->getUserProfile();

The problem with that was you really need to put it into the session to use it in your controllers, but when PHP unserialised the session (at session_start()), because it couldn’t autoload the Hybrid_Auth classes, it threw an error and died.

Doing:




$ha = Yii::app()->getModule('hybridauth')->getHybridAuth();



means that Hybrid_Auth gets init’d correctly, and you can then get the adapter directly from there, without needing to worry about manually loading all the Hybrid_Auth classes yourself, before session_start();

Hi,

I’m now trying out your module, and it works fine, but might I suggest you use the Yii::app()->createAbsoluteUrl() method to create the URLs because not everyone uses the urlManager the same way, and things might go wrong.

Good job.

Firstly, thanks to markvr for excellent job on this extension!

Secondly, anyone know why twitter might not be working? Facebook works absolutely fine but when I try to use twitter an error stops the app. The error doesn’t clear until I wipe the cookies to clear the session.

The error contains the following in stack trace:


–  /home/snowglo/public_html/protected/modules/hybridauth/Hybrid/Storage.php(25): unserialize("O:9:"Exception":7:{s:10:"*message";s:69:"Authentification fail...")

And the top message is:


include(DefaultController.php) [<a href='function.include'>function.include</a>]: failed to open stream: No such file or directory

DefaultController.php does exist so I can’t explain why that’s been reported, but the issue seems to be that twitter auth is failing and, despite double checking the public key and secret, I can’t see why…

any ideas?

+1 for using more flexible url creation, it is not possible to use this extension when locale is part of the url.

Also, it will be nice to add support of CSRF.

It is possible to validate CSRF throuth GET parameter (see this solution)

Also, it will be good compatibility improvement to rewrite db table defination according to Yii db convention http://www.yiiframework.com/doc/guide/1.1/en/basics.convention#database and update appropriate model class.

Hi,

Nice addon.

But i have question:

Why, when an user accept the terms of the social network’s application, you will ask username & email in the next step?

Is more better to let choose a password and a display name.

The email can be get in social account. or im wrong?

Using with the yii-user, I have to create the user name and enter the email. I could not do this automatically? The WP plugin to do. Thank you.

Hello,

I have an issue. I am a new Yii user. I followed all the steps of the presentation page but I have an issue. When I click on Twitter or Facebook it redirect me to:

****://localhost:8084/hybridauth/default/login/?provider=facebook

Then I am getting a 404 error.

My config is:




'hybridauth' => array(

			'baseUrl' => '****://localhost:8084' . '/hybridauth',

			"providers" => array (


				"facebook" => array (

					"enabled" => true,

					"keys"    => array ( "id" => "AA", "secret" => "BB" ),

					"scope"   => "email,publish_stream",

					"display" => "Texte pour facebook"

				),


				"twitter" => array (

					"enabled" => true,

					"keys"    => array ( "key" => "AA", "secret" => "BB" )

				)

			)

        ),



I used **** because I cannot post links

I think this is related to URL MANAGER

What should I do to fix this?