0
我试图使用OAuth2 for Elixir获取访问令牌以与Google Cloud Storage API进行交互。我一直在尝试OAuth2 Playground,我可以提出请求,然后他们将令牌给我。在做基本的GET请求(列出项目中的桶)时,它一切正常,但我当然需要在应用程序中自动获取令牌,而不是复制粘贴。Google Cloud Storage - 试图在Elixir中获得访问令牌
def token do
client = OAuth2.Client.new([
strategy: OAuth2.Strategy.AuthCode, #default
client_id: "myClientID",
client_secret: "myClientSecret",
site: "https://www.googleapis.com",
redirect_uri: "https%3A%2F%2Fdevelopers.google.com%2Foauthplayground" #I HAVE NO IDEA WHAT SHOULD BE HERE???
])
token =
client
|> OAuth2.Client.put_param(:code, "myAuthCode")
|> OAuth2.Client.get_token!()
我总是收到“未找到”消息。
我对此很困惑,如果有人能帮助我,我会非常感激。
编辑:
显然,请求应该是这样的:
https://accounts.google.com/o/oauth2/v2/auth?response_type=token&client_id=myClientID&nonce=someRandomStringIthink&scope=https://www.googleapis.com/auth/devstorage.full_control&redirect_uri=WHEREDOIGETTHIS
我仍然不知道在哪里可以找到重定向URI。文档说它应该在开发者的控制台中。
redirect_uri应该是您的应用程序的回调URL。在Google上创建应用时,您可能会指定这一点。 – Gazler