【问题标题】:Google | OAuth 400 redirect_uri_mismatch谷歌 | OAuth 400 重定向_uri_mismatch
【发布时间】: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


【解决方案1】:

您不能在单引号内使用反引号运算符。第三行应该是

$redirect_uri = 'http://'.`localhost`.'/joomla/index.php?option=com_component&view=quest&task=signup'; 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-08-15
    • 2013-12-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-05
    • 1970-01-01
    相关资源
    最近更新 更多