在Go中无人值守授权Google API

huangapple go评论81阅读模式
英文:

Unattended authorisation to Google API in Go

问题

我一直在尝试找到一种在不需要用户每次重新授权的情况下与Google的API(特别是Compute Engine API)进行交互的方法。

由于请求将在没有用户存在的情况下进行,所以绝对必须避免通过同意屏幕进行授权。

我正在使用Go语言和Go API客户端库。

有人可以解释一种实现我所需的方法吗?

英文:

I've been trying to find a way to interact with Google's API (specifically, the Compute Engine API) without having the user authorise via a consent screen each time I need to reauthorise with Google.

The requests will be made when no user is present, so not having to authorise via a consent screen is an absolute must.

I'm using Go and the Go API Client Library.

Can anybody explain a method to achieve what I need to?

答案1

得分: 3

你应该查看一下服务账号。它们使用公钥/私钥对来授权调用Google API。

Google开发者文档中有一份非常好的说明服务账号工作原理的文档:

https://developers.google.com/accounts/docs/OAuth2ServiceAccount

以下是如何生成服务账号的步骤:

https://developers.google.com/console/help/new/#serviceaccounts

你也会在第一个文档中找到代码示例,但不幸的是没有Go语言的示例。
不过,我在这里找到了一些评论:

https://code.google.com/p/google-api-go-client/wiki/GettingStarted

希望对你有所帮助。

英文:

You should take a look at service accounts. They utilize the public/private key pair to authorize calls to Google API.

Google Developers has one very nice document explaining how service accounts work:

https://developers.google.com/accounts/docs/OAuth2ServiceAccount

Here's how generate a service account:

https://developers.google.com/console/help/new/#serviceaccounts

You will also find the code samples in the first doc, but unfortunately not in Go.
However, there are some comments that I found here:

https://code.google.com/p/google-api-go-client/wiki/GettingStarted

Hope it helps.

huangapple
  • 本文由 发表于 2014年8月12日 02:42:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/25250217.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定