【发布时间】:2014-09-09 07:35:49
【问题描述】:
我想创建 google 身份验证但找不到错误: 我在下面有一个代码:
$client_id = 'xxxxxxx-4bsrudsadhna5817fddlhmf02ihgrcr0.apps.googleusercontent.com';
$client_secret = 'xxxxxxxxxxxxxxxxxx';
$redirect_uri = 'http://`localhost`/joomla/index.php?option=com_component&view=quest&task=signup';
$url = 'https://accounts.google.com/o/oauth2/auth';
$params = array(
'redirect_uri' => $redirect_uri,
'response_type' => 'code',
'client_id' => $client_id,
'scope' => 'https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile'
);
$this->google_auth_link = $url . '?' . urldecode(http_build_query($params));
echo '<a href="'.$this->google_auth_link.'">Login using Google +</a>';
但这让我回想起:
400 - That’s an error.
Error: redirect_uri_mismatch
请求中的重定向 URI:http://localhost/joomla/index.php?option=com_component 与注册的重定向 URI 不匹配
P.S 似乎这部分 URI 已被删除:&view=quest&task=signup
谢谢!
【问题讨论】:
-
你为什么在这里使用
urldecode?这完全没有意义。 -
这很奇怪,但没有 urldecode 这个代码可以工作!为什么?
-
因为只有这样,您传递的参数才能正确地进行 URL 编码,
http_build_query负责处理 - 并且故意还原您正在搞砸的情况。
标签: php authentication joomla oauth