[MODULE] HybridAuth

Here is what am getting http://www.sitename.com/hybridauth/default/login/?provider=Facebook#=

Look at the url this is after logging in with facebook then redirects to my site. Also it gives me a form to register and am already a registered user in my site.

Hi all,

I am trying that the user never disconnects ( 1 month ) from my app so i extend session time.


Yii::app()->user->login($identity,2628000); // One month

And php.ini session_lifeTime too. 

But after a time facebook token dies and no more info is retrieved from FB .

I found that this token expire after two hours.

How i can manage that?

Thanks in advance.

Nice module, keep up the good work!

I test-drove it (Facebook only) today. Here are my installation steps. As I am very new to Yii I had a bit of the struggle. Hope this helps somebody else as well.

1. Created a new facebook app

According to: hybridauth.sourceforge.net/userguide/IDProvider_info_Facebook.html). Important to set your Site url in Facebook exactly the same as in config file baseUrl parameter.

2. Created a Yii skeleton app.

3. Made changes in protected/config/main.php

Uncommented the url manager, added .htaccess (see www.yiiframework.com/doc/guide/1.1/en/quickstart.apache-nginx-config)file to website root dir.

4. Created 2 new tables in default (testdrive) sqlite database:

CREATE TABLE [ha_logins] (

[id] INTEGER PRIMARY KEY AUTOINCREMENT,

[userId] int(11) NOT NULL,

[loginProvider] varchar(50) NOT NULL,

[loginProviderIdentifier] varchar(100) NOT NULL);

I know, MySQL table, provided in the extension description, had a lot more keys and indexes.

For User model:

CREATE TABLE [user] (

[id] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,

[username] VARCHAR(128) NOT NULL,

[password] VARCHAR(128),

[email] VARCHAR(128) NOT NULL);

(Notice the password can be null)

5. Create a User model (either with gii or yiic)

The user module does not work normally yet, this is only for testing hybridauth. For exampl see: www.yiiframework.com/doc/blog/1.1/en/prototype.auth

6. Paste the configuration data into main.php

Make required changes (baseUrl, app-ids, and secrets).

Important! If you are using Linux server, change provider indexes first letter to upper case (see the 1st comment on the extension page).

7. Unpack extension to newly created protected/modules dir

Go to: your-path/dir/hybridauth and click on facebook icon.

I know this is probably an easy question to answer, but I cannot figure out what I didn’t do during the setup. It looks close to what you were discussing, but apparently you are able to get farther than I do.

I copied the widget from the extension page


<?php $this->widget('application.modules.hybridauth.widgets.renderProviders'); ?>

and added the module to my config file and tried to add the widget to one of my pages, but I keep getting the following error when I click on one of the social icons:


The requested URL /hybridauth/default/login/ was not found on this server.

It seems my code cannot "see" the hybridauth module or the default controller in the module. I am not sure what else to change for this.

Sorry if this is a stupid question.

Ok, I just saw where you have to add index.php/ to the base_url. It got me past that point and to the login at least.

Hi

What is the correct url for accessing the content?

I tried with and without the index.php but with no joy

None of these urls worked, I keep getting a page not found.

I also tried this out on a box that had a dns url assigned to it but that didnt work either

I tried the sample a few times, with blank yii projects but no good

Any assistance on this is greatly appreciated

Great extension. My site already has a registration system with User table and UserProfile table so I changed it slightly to call a custom Registration page so you can implement your own registration. Might be worth including something like this in future releases?

Extract Register (createUser) from _doLogin into its own method with protected access. Also make _linkProvider protected

DefaultController.php




	private function _doLogin() {

		....

		} else if ($identity->errorCode == RemoteUserIdentity::ERROR_USERNAME_INVALID) {

			// They have authenticated to their provider but we don't have a matching HaLogin entry

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

				$this->registerUser($identity);

			} else {

				// They are already logged in, link their user account with new provider

				...

			}

		}

	}


	/**

	 * Overridable method to display a custom Registration page if desired

	 * Overrides should make sure to call the following method to link the user to the provider 

	 * 	$this->_linkProvider($identity);

	 * 

	 * @param RemoteUserIdentity $identity

	 */

	protected function registerUser($identity) {

		// They aren't logged in => display a form to choose their username & email

		// (we might not get it from the provider)

		if ($this->module->withYiiUser == true) {

			Yii::import('application.modules.user.models.*');

		} else {

			Yii::import('application.models.*');

		}

		

		$user = new User;

		if (isset($_POST['User'])) {

			//Save the form

			$user->attributes = $_POST['User'];

		

			if ($user->validate() && $user->save()) {

				if ($this->module->withYiiUser == true) {

					$profile = new Profile();

					$profile->first_name='firstname';

					$profile->last_name='lastname';

					$profile->user_id=$user->id;

					$profile->save();

				}

		

				$identity->id = $user->id;

				$identity->username = $user->username;

				$this->_linkProvider($identity);

				$this->_loginUser($identity);

			} // } else { do nothing } => the form will get redisplayed

		} else {

			//Display the form with some entries prefilled if we have the info.

			if (isset($identity->userData->email)) {

				$user->email = $identity->userData->email;

				$email = explode('@', $user->email);

				$user->username = $email[0];

			}

		}

		

		$this->render('createUser', array(

				'user' => $user,

		));

	}




Then create a new Controller that extends DefaultController and override the method to display your onw custom Registration page

CustomController.php




Yii::import('application.modules.hybridauth.controllers.DefaultController');


class CustomController extends DefaultController {

	

	protected function registerUser($identity) {

            // Your custom Code here

        }

}



Then set the default controller in the Module config

main.php




'hybridauth' => array(

    .....

    'defaultController'=>'custom',

    ....

),



And lastly i had to update render providers widget to use the defaultController as specified in the module rather than the currently hardcoded default controller

providers.php




<?php $controller = Yii::app()->getModule('hybridauth')->defaultController; ?>

....

<form action="<?php echo $this->config['baseUrl'];?>/<?php echo $controller; ?>/login/" method="get" id="hybridauth-openid-form" >

....

<form action="<?php echo $this->config['baseUrl'];?>/<?php echo $controller; ?>/unlink" method="post" id="hybridauth-unlink-form" >

....

<a id="hybridauth-<?php echo $provider ?>" href="<?php echo $baseUrl?>/<?php echo $controller; ?>/login/?provider=<?php echo $provider ?>" >

....



Any suggestions/comments welcome!

Thanks

Ross

One other thing, if your server runs on unix the config is case sensitive! I had ‘facebook’=> array() but the provider files called Facebook.php which threw an error. Had to change it to ‘Facebook’=> array()

When a page provider, I press "Cancel", I redirect to the page:

_http://site/hybridauth/default/login/?provider=provider

The error occurs here:

/protected/modules/hybridauth/Hybrid/Storage.php(25):


return unserialize( $_SESSION["HA::STORE"][$key] ); 

Please help

Hi

I am using your plugin to integrate several social logins on a project, including Facebook.

I am facing a problem that I can’t trace anywhere and that is that even if I set display => popup for FB, it opens the facebook connect page normally instead of in a popup which results in the user leaving the website.

Here’s what I use in my view:


<?php $this->widget('application.modules.hybridauth.widgets.renderProviders'); ?>

and here’s what I have in my config:


"Facebook" => array(

                    "enabled" => true,

                    "keys" => array("id" => "XXXXXX", "secret" => "XXXXXX"),

                    "scope" => "",

                    "display" => "popup"

                ),

I have a feeling that something might have to be changed in the widget view to account for this, but anything I’ve tried didn’t work. Shouldn’t there be some sort of JS registered for Facebook?

I have the same problem. If I try to login with Facebook, then press cancel on the Facebook auth screen I see this error. I’ll continue to investigate but if anyone already has a solution…?

This issue didn’t occur in an older version of this module that I used before.

‘import’=>array(

‘application.models.*’,

‘application.components.*’,

//for hybridauth

‘application.modules.hybridauth.controllers.*’,

)

Add the path to DefaultController.php for the autoloader into the config file.

Maybe, there is a better solution with require.

I had already tried that - it didn’t work. This turned out to be a problem with the sessions used in Hybridauth being overwritten by the sessions in Yii. The module doesn’t seem to work at all with Yii sessions auto-starting. It works fine with sessions turned off.

I’m getting an error “include(DefaultController.php): failed to open stream: No such file or directory” and some weird characters get added to the url “#=”. I’m testing this on localhost and using just facebook. I understand this has been reported by other members in the thread too, so has anyone found out the solution to this and what’s causing this?

It works for me with the import line. My sessions are autostarted.

I’ve updated the directory Hybrid with the files from hybridauth.sourceforge.net/

Google works. Now, they use OAuth for Yahoo, I need to verify the config for it.

hey guys how much time do you think it takes to implement this extension only to provide facebook connect to my site? i need to estimate an amount of time for my project. i only have name email password country and date of birth in my login form. And im brand new (1 month) with yii

Kindly follow the vincenze instructions, the default controller error will not occur. It is working fine for me with those instructions. Refer #92

Maximum 2 hours.

Plz refer #92

When i tried to update status with hybridauth it throws error

Array ( [Post] => Array ( [receiver_type] => 0 [receiver_id] => 2 [message] => faf ) [socialmedia] => Array ( [facebook] => 1 [twitter] => 1 [linkedin] => 1 ) )

Exception

Update user status update failed! LinkedIn returned an error.