Login Google OAuth 2.0的故障排除-来自Google的查询分隔符不正确';s服务器

Login Google OAuth 2.0的故障排除-来自Google的查询分隔符不正确';s服务器,login,oauth-2.0,Login,Oauth 2.0,login.php <?php define('client_id', 'cid'); define('redirect_uri', 'http://domain.tld/file.php'); define('client_secret', 'secret'); $endpoint = 'https://accounts.google.com/o/oauth2/auth'; $querystr = array( 'respons

login.php

<?php
    define('client_id', 'cid');
    define('redirect_uri', 'http://domain.tld/file.php');
    define('client_secret', 'secret');


    $endpoint = 'https://accounts.google.com/o/oauth2/auth';
    $querystr = array(
        'response_type' => 'token',
        'client_id' => client_id,
        'redirect_uri' => redirect_uri,
        'scope' => 'https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile',
#       'state' => $_SERVER['REQUEST_URI']
    );


    if (isset($_GET['access_token']))
        print_r($_GET);
    else
        header('Location: ' . $endpoint . '?' . http_build_query($querystr));

?>

上面的代码工作得很好,我遇到的问题是,我从谷歌得到的回复格式不好。我从他们那里得到的查询字符串不是以问号开始的
,而是以数字符号开始的
。下面是从Google服务器上检索的一个示例

http://domain.tld/file.php#access_token=ya29.AHES6ZABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmno&token_type=Bearer&expires_in=3600


为什么要用数字符号将查询字符串与文件路径分开?这是因为我没有使用https模式,这是对我的惩罚?

不。它被称为URL的“哈希”。对于从服务器到客户端的响应(反之亦然),这是一种常见的方案。例如,FacebookOAuth2.0也使用这种技术。只要习惯它,并解释从散列符号开始的响应。

我将response_类型更改为code,并得到一个普通的查询字符串。谢谢你的帮助!我不知道这是正常的。你能补充一些他们为什么使用URL哈希的细节吗?我不知道确切的原因;我想是吧?“更多”表示对服务器的查询。