我正在使用带有 CakePHP 的 HybridAuth2,我的控制器功能为
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);
}
}
混合身份验证库位于应用文件夹下的 Web 根文件夹中
但是,我收到的情况 6 中的错误,即
案例 6:$error ="用户配置文件请求失败。用户很可能没有连接到提供商,他应该再次进行身份验证。
确切的错误消息是Undefined variable: adapter [APP'Controller'UsersController.php, line 177]
指向案例 6
谁能建议发生了什么。我无法调试这个。
附言这只发生在谷歌登录
问候枪
您的问题已有半年多了,但您可以找到解决方案:
转到 https://console.developers.google.com/并激活 Google+ API 访问权限。
我今天早些时候遇到了这个问题,这解决了!