SocalNick / ScnSocialAuth

Uses the HybridAuth PHP library to Enable authentication via Google, Facebook, Twitter, Yahoo!, etc for the ZfcUser ZF2 module.
BSD 3-Clause "New" or "Revised" License
216 stars 110 forks source link

Auth event was stopped without a response. Got "boolean" instead. #209

Closed Mr-Penguin closed 8 years ago

Mr-Penguin commented 9 years ago

Get the error when trying to login with Facebook. (This error happens after I logged in to Facebook) Saw a similar issue here, issue:91.

Stacktrace:

#0 /var/www/rogatio3/vendor/zf-commons/zfc-user/src/ZfcUser/Controller/UserController.php(151): ZfcUser\Authentication\Adapter\AdapterChain->prepareForAuthentication(Object(Zend\Http\PhpEnvironment\Request))
#1 /var/www/rogatio3/vendor/zendframework/zend-mvc/src/Controller/AbstractActionController.php(82): ZfcUser\Controller\UserController->authenticateAction()
#2 [internal function]: Zend\Mvc\Controller\AbstractActionController->onDispatch(Object(Zend\Mvc\MvcEvent))
#3 /var/www/rogatio3/vendor/zendframework/zend-eventmanager/src/EventManager.php(444): call_user_func(Array, Object(Zend\Mvc\MvcEvent))
#4 /var/www/rogatio3/vendor/zendframework/zend-eventmanager/src/EventManager.php(205): Zend\EventManager\EventManager->triggerListeners('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
#5 /var/www/rogatio3/vendor/zendframework/zend-mvc/src/Controller/AbstractController.php(118): Zend\EventManager\EventManager->trigger('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
#6 /var/www/rogatio3/vendor/zendframework/zend-mvc/src/Controller/Plugin/Forward.php(142): Zend\Mvc\Controller\AbstractController->dispatch(Object(Zend\Http\PhpEnvironment\Request), Object(Zend\Http\PhpEnvironment\Response))
#7 /var/www/rogatio3/vendor/socalnick/scn-social-auth/src/ScnSocialAuth/Controller/UserController.php(162): Zend\Mvc\Controller\Plugin\Forward->dispatch('zfcuser', Array)
#8 /var/www/rogatio3/vendor/zendframework/zend-mvc/src/Controller/AbstractActionController.php(82): ScnSocialAuth\Controller\UserController->providerAuthenticateAction()
#9 [internal function]: Zend\Mvc\Controller\AbstractActionController->onDispatch(Object(Zend\Mvc\MvcEvent))
#10 /var/www/rogatio3/vendor/zendframework/zend-eventmanager/src/EventManager.php(444): call_user_func(Array, Object(Zend\Mvc\MvcEvent))
#11 /var/www/rogatio3/vendor/zendframework/zend-eventmanager/src/EventManager.php(205): Zend\EventManager\EventManager->triggerListeners('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
#12 /var/www/rogatio3/vendor/zendframework/zend-mvc/src/Controller/AbstractController.php(118): Zend\EventManager\EventManager->trigger('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
#13 /var/www/rogatio3/vendor/zendframework/zend-mvc/src/DispatchListener.php(93): Zend\Mvc\Controller\AbstractController->dispatch(Object(Zend\Http\PhpEnvironment\Request), Object(Zend\Http\PhpEnvironment\Response))
#14 [internal function]: Zend\Mvc\DispatchListener->onDispatch(Object(Zend\Mvc\MvcEvent))
#15 /var/www/rogatio3/vendor/zendframework/zend-eventmanager/src/EventManager.php(444): call_user_func(Array, Object(Zend\Mvc\MvcEvent))
#16 /var/www/rogatio3/vendor/zendframework/zend-eventmanager/src/EventManager.php(205): Zend\EventManager\EventManager->triggerListeners('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
#17 /var/www/rogatio3/vendor/zendframework/zend-mvc/src/Application.php(314): Zend\EventManager\EventManager->trigger('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
#18 /var/www/rogatio3/public/index.php(17): Zend\Mvc\Application->run()
#19 {main}

Is it just me or is there something broken?

If I var_dump the event ($e) at AdapterChain.php#L63my page will get miles long. Your help is as always appreciated.

PS: zfc-user version v1.2.2 scnsocial v1.17.2 hybridauth v2.4.1

spatsatzis commented 9 years ago

+1 me too !! installed manually and with composer too , the same error !!

If i downgrade ZfcUser to 0.1.2 it skips the error and redirects to login page with error message "Authentication failed"

yevhenii-myronov commented 9 years ago

Yes, the same problem. Auth event was stopped without a response. Got "boolean" instead

SocalNick commented 9 years ago

You are likely getting to one of the error cases in this class: https://github.com/SocalNick/ScnSocialAuth/blob/master/src/ScnSocialAuth/Authentication/Adapter/HybridAuth.php

Can you add some debugging to determine where it is bailing out of the authenticate method?

yevhenii-myronov commented 9 years ago

'email' => string '' 'emailVerified' => string '' and throw exception on https://github.com/SocalNick/ScnSocialAuth/blob/master/src/ScnSocialAuth/Authentication/Adapter/HybridAuth.php#L359-L360 Please verify your email with Facebook before attempting login

SocalNick commented 9 years ago

If someone would like to explore what it would take to deliver a better message to the user, I'd be happy to look at a PR.

spatsatzis commented 9 years ago

ScnSocialAuth\Authentication\Adapter\HybridAuth in function authenticate and line 112.

If you add var_dump($ex); die();

You will get the RuntimeException , with the error message

["message":protected]=> string(62) "Please verify your email with Facebook before attempting login"

Which means the problem is in line 357 function facebookToLocalUser

then i tried a var_dump to $userProfile and as wizard2014 said the result is

["email"]=> string(0) "" ["emailVerified"]=> string(0) ""

strange because i added email at my scope !

So searching in depth , seems that the problem is in the hybridauth library.

hybridauth/hybridauth/hybridauth/Hybrid/Providers/Facebook in function getUserProfile

line 163

$data = $this->api->api('/me');

and some lines after this we have lines like this

$this->user->profile->email = (array_key_exists('email',$data))?$data['email']:"";

Every $this->user->profile->xxx property will be "" because $data is an array with only name and id !!

If you manually add $data = $this->api->api('/me?fields=email'); it will return email too !

So i think there is the problem !

SocalNick commented 9 years ago

I don't think this is a problem with HybridAuth. Users need to verify their email with Facebook before HybridAuth / ScnSocialAuth should authenticate the user.

This module needs to properly display the error message to the user. I'll gladly review a PR to fix.

spatsatzis commented 9 years ago

I don't think it has to do with the facebook account details !

"Users need to verify their email with Facebook before HybridAuth / ScnSocialAuth should authenticate the user."

My facebook email is verified !

As i said the return data from facebook are only the id and name but if i ask for email it returns the email too !

yevhenii-myronov commented 9 years ago

Yes, that is right. If we manually add '/me?fields=email' we'll get email.

casperfrx commented 9 years ago

Same problem here. Anyone got a quick fix for now?

spatsatzis commented 9 years ago

https://github.com/hybridauth/hybridauth/commit/e8015af23cc9b5aaa3755508b4d8117df8ceda5a

casperfrx commented 9 years ago

Nice! But this is a master branch. Seeing as how they are working on a 3.0.0 version I'm assuming it will be in there. Question that rises is whether ScnSocialAuth will still support it, since it asks for 2.4.* now. I'll test it out later.

casperfrx commented 9 years ago

Still getting the error with the latest commit. Anyone else who can confirm this?

Mr-Penguin commented 9 years ago

@CasperF Nope, I tried what @invader7 posted and it worked for me. Thanks for the post.

yevhenii-myronov commented 9 years ago

@invader7. Yes, it works.

SocalNick commented 9 years ago

Looks like the commit is on master which is 2.4.2-dev. Just need to wait for them to cut a 2.4.2 final release.

timoziemann commented 9 years ago

Will there be support for 2.5 of HybridAuth any time soon? I'm getting the error described above if i put in 'email' as the facebook scope. I'm just getting started with this... :) thx!

SocalNick commented 8 years ago

Fixed in https://github.com/SocalNick/ScnSocialAuth/releases/tag/1.18.0