Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Oauth 2.0 将Google OAUTH2.0与Hyperledger Composer REST服务器一起使用时无法获取用户信息_Oauth 2.0_Hyperledger Fabric_Hyperledger Composer_Google Oauth - Fatal编程技术网

Oauth 2.0 将Google OAUTH2.0与Hyperledger Composer REST服务器一起使用时无法获取用户信息

Oauth 2.0 将Google OAUTH2.0与Hyperledger Composer REST服务器一起使用时无法获取用户信息,oauth-2.0,hyperledger-fabric,hyperledger-composer,google-oauth,Oauth 2.0,Hyperledger Fabric,Hyperledger Composer,Google Oauth,我已经按照说明构建了一个REST服务器 我成功了。然后,我使用angular为客户机构建了一个应用程序。在用户登录并成功与REST服务器api交互后,我获得了令牌 问题是,当我使用此令牌获取用户信息,如姓名、电子邮件等时。。。从GoogleAPI中,它总是返回一个“无效凭据”错误。我用来获取信息的API是https://www.googleapis.com/oauth2/v3/userinfo 例:https://www.googleapis.com/oauth2/v3/userinfo?acc

我已经按照说明构建了一个REST服务器 我成功了。然后,我使用angular为客户机构建了一个应用程序。在用户登录并成功与REST服务器api交互后,我获得了令牌

问题是,当我使用此令牌获取用户信息,如姓名、电子邮件等时。。。从GoogleAPI中,它总是返回一个“无效凭据”错误。我用来获取信息的API是
https://www.googleapis.com/oauth2/v3/userinfo

例:
https://www.googleapis.com/oauth2/v3/userinfo?access_token=u2dDxaEeECKPAv6HlhQ1eMULWNADvVDHbGTlUjnS7jfUII0fwiHvkzYGD0FmZjuf


我有什么问题?欢迎提出任何想法。

端点
https://www.googleapis.com/oauth2/v3/userinfo
需要授权

这意味着您需要包含HTTP头
Authorization:Bearer
来调用此端点

以下是Go中的一个示例:

func displayUserInfo(accessToken string) {
        endpoint := "https://www.googleapis.com/oauth2/v3/userinfo"

        req := HttpRequest.NewRequest()

        req.SetHeaders(map[string]string{"Authorization": "Bearer " + accessToken})

        res, err := req.Get(endpoint)

        if err != nil {
                fmt.Println("Error: ", err)
                return
        }

        body, err := res.Body()

        if err != nil {
                fmt.Println("Error: ", err)
                return
        }

        fmt.Println(string(body))
}