【问题标题】:Google Cloud Admin authentication谷歌云管理员身份验证
【发布时间】:2020-03-12 23:01:27
【问题描述】:

参考以下链接https://cloud.google.com/sql/docs/mysql/admin-api/how-tos/authorizing。我已经尝试过 apikey 但没有成功。 API 的响应如下;

//https://www.googleapis.com/sql/v1beta4/projects/<projectid>/instances/<instanceid>/databases?key=<API_KEY>

{
    "error": {
        "code": 401,
        "message": "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
        "errors": [
            {
                "message": "Login Required.",
                "domain": "global",
                "reason": "required",
                "location": "Authorization",
                "locationType": "header"
            }
        ],
        "status": "UNAUTHENTICATED"
    }
}

我对 oAUth 2.0 没有任何问题,因此想确认是否不再支持通过 api 密钥进行授权?

【问题讨论】:

    标签: api google-cloud-platform google-cloud-sql


    【解决方案1】:

    我测试了仅使用 API 密钥从端点获取信息并且无法检索信息,因为必须使用身份验证承载。

    我使用这些命令来获取数据库信息

    export TOKEN=`gcloud auth application-default print-access-token`
    
    curl -X GET \
      https://sqladmin.googleapis.com/sql/v1beta4/projects/[MY PROJECT ID]/instances/[MY INSTANCE NAME]/databases \
      -H 'authorization: Bearer '"$TOKEN"''
    

    由于此请求包含敏感数据(非公开),因此 OAuth 令牌和 api 密钥不是必需的,如 document 所述。

    看起来 key 参数不再需要了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-11-01
      • 2018-10-20
      • 1970-01-01
      • 2021-12-20
      • 2011-09-18
      • 2014-07-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多