【发布时间】:2013-11-27 10:27:16
【问题描述】:
我正在使用 HybridAuth2 和 CakePHP,我的控制器功能是
public function loginwith($provider) {
// $this->autoRender = false;
require_once( WWW_ROOT . 'hybridauth/Hybrid/Auth.php' );
$hybridauth_config = array(
"base_url" => 'http://' . $_SERVER['HTTP_HOST'] . $this->base . "/hybridauth/", // set hybridauth path
"providers" => array(
"Google" => array(
"enabled" => true,
"keys" => array("id" => "clientID", "secret" => "clientSecret")
)
)
);
try {
// create an instance for Hybridauth with the configuration file path as parameter
$hybridauth = new Hybrid_Auth($hybridauth_config);
// try to authenticate the selected $provider
$adapter = $hybridauth->authenticate($provider);
// grab the user profile
$user_profile = $adapter->getUserProfile();
debug($user_profile);
} catch (Exception $e) {
// Display the recived error
switch ($e->getCode()) {
case 0 : $error = "Unspecified error.";
break;
case 1 : $error = "Hybriauth configuration error.";
break;
case 2 : $error = "Provider not properly configured.";
break;
case 3 : $error = "Unknown or disabled provider.";
break;
case 4 : $error = "Missing provider application credentials.";
break;
case 5 : $error = "Authentification failed. The user has canceled the authentication or the provider refused the connection.";
break;
case 6 : $error = "User profile request failed. Most likely the user is not connected to the provider and he should to authenticate again.";
$adapter->logout();
break;
case 7 : $error = "User not connected to the provider.";
$adapter->logout();
break;
}
// well, basically you should not display this to the end user, just give him a hint and move on..
$error .= "Original error message: " . $e->getMessage();
$error .= "Trace: " . $e->getTraceAsString();
$this->set('error', $error);
}
}
HybridAuth 库位于 app 文件夹下的 webroot 文件夹中
但是,我得到了 case 6 中的错误,即
case 6 : $error = "用户配置文件请求失败。很可能用户没有连接到提供者,他应该再次进行身份验证。";
确切的错误消息是 Undefined variable: adapter [APP\Controller\UsersController.php, line 177],它指向 CASE 6
任何人都可以建议发生了什么。我无法调试这个。
附注这只发生在 Google 登录
问候, 枪
【问题讨论】:
-
我知道它现在已经相当老了,但我也刚刚得到它,不知道我是如何创建它的。我必须去 security.google.com/settings/security/permissions?pli=1 并从 Google 撤消我的网络应用程序并重新登录。我真的很想知道是什么原因造成的。
标签: php cakephp hybridauth hybridauthprovider