Google Container Engine REST API Authorization

邮差的信 提交于 2019-12-25 05:30:40

问题


As mentioned here I created API key for using cluster operations.

For example for this query:

https://www.googleapis.com/container/v1beta1/projects/PROJECT_ID/clusters

And as mentioned

After you have an API key, your application can append the query parameter key=yourAPIKey to all request URLs.

I added it to url:

https://www.googleapis.com/container/v1beta1/projects/PROJECT_ID/clusters?key=my_key

But i have error:

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "required",
    "message": "Login Required",
    "locationType": "header",
    "location": "Authorization"
   }
  ],
  "code": 401,
  "message": "Login Required"
 }
}

I even tried to add key to Authorization part of header...and had this error:

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "authError",
    "message": "Invalid Credentials",
    "locationType": "header",
    "location": "Authorization"
   }
  ],
  "code": 401,
  "message": "Invalid Credentials"
 }
}

Where is problem? Or did i something wrong?


回答1:


According to the Google help documentation for API Keys (emphasis added):

An API key (either a server key or a browser key) is a unique identifier that you generate using the Developers Console. Using an API key does not require user action or consent. API keys do not grant access to any account information, and are not used for authorization.

Furthermore, it says that they can be used to access data that is public or owned by a Google service. The Google Container Clusters (GKE) data is neither of these. I'm not sure why the documentation suggests using an API key, but I know that OAuth works so if you can use that instead you should be able to get the REST API working.



来源:https://stackoverflow.com/questions/28718370/google-container-engine-rest-api-authorization

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!