我们在使用Facebook身份验证时遇到问题。我们使用phalcon,并且使用php-sdk-v4插件进行身份验证。当我们尝试登录时,我们有太多重定向的错误。我们的网站是https://app.wowego.com/register。有帮助吗?
代码: 文件:AUTH.PHP
public function loginWithFacebook()
{
$di = $this->getDI();
$facebook = new FacebookConnector($di);
$facebookUser = $facebook->getUser();
if (!$facebookUser) {
$scope = [
'scope' => 'email,user_birthday,user_location',
];
return $this->response->redirect($facebook->getLoginUrl($scope), true);
}
try {
return $this->authenticateOrCreateFacebookUser($facebookUser);
} catch (\FacebookApiException $e) {
$di->logger->begin();
$di->logger->error($e->getMessage());
$di->logger->commit();
$facebookUser = null;
}
}
FACEBOOKCONNECTOR.PHP
public function __construct($di)
{
$this->di = $di;
$fbConfig = $di->get('config')->pup->connectors->facebook;
$protocol = strtolower(substr($_SERVER['SERVER_PROTOCOL'], 0, strpos($_SERVER['SERVER_PROTOCOL'], '/'))).'://';
$protocol="https://";
if (isset($fbConfig['route'])) {
$this->url = $protocol.$_SERVER['HTTP_HOST'].$fbConfig['route'];
} else {
$this->url = $protocol.$_SERVER['HTTP_HOST'].'/usercontrol/loginwithfacebook';
}
//echo $this->url;die();
FacebookSession::setDefaultApplication($fbConfig->appId, $fbConfig->secret);
}
public function getLoginUrl($scope = [])
{
$this->helper = new FacebookRedirectLoginHelper($this->url);
return $this->helper->getLoginUrl($scope);
}
/**
* Get facebook user details.
*
* @return unknown|bool
*/
public function getUser()
{
try {
$this->helper = new FacebookRedirectLoginHelper($this->url);
$this->fb_session = $this->helper->getSessionFromRedirect();
} catch (FacebookRequestException $ex) {
$this->di->get('flashSession')->error($ex->getMessage());
} catch (\Exception $ex) {
$this->di->get('flashSession')->error($ex->getMessage());
}
if ($this->fb_session) {
$request = new FacebookRequest($this->fb_session, 'GET', '/me?fields=id,first_name,last_name,email');
$response = $request->execute();
$fb_user = $response->getGraphObject()->asArray();
return $fb_user;
}
return false;
}
USERCONTROLLER.PHP
public function loginwithfacebookAction()
{
try {
//echo "dentro del try";
$this->view->disable();
$fopen = fopen('../logs/loginWithFacebook.log');
fwrite( $this->auth->loginWithFacebook() , $fopen );
fclose( $fopen );
return $this->auth->loginWithFacebook();
} catch(AuthException $e) {
$this->flash->error('There was an error connectiong to Facebook.');
}
}
答案 0 :(得分:0)
我无法对其进行测试,但这似乎是循环的:在facebookconnector.php
中,if导致对静态函数FacebookSession::setDefaultApplication
的相同调用。您可以尝试:
if (isset($fbConfig['route'])) {
$this->url = $protocol.$_SERVER['HTTP_HOST'].$fbConfig['route'];
FacebookSession::setDefaultApplication($fbConfig->appId, $fbConfig->secret);
} else {
$this->url = $protocol.$_SERVER['HTTP_HOST'].'/usercontrol/loginwithfacebook';
return $this->response->redirect($this->url);
}