2016-03-04 48 views
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。文檔說它應該在開發者的控制檯中。

+2

redirect_uri應該是您的應用程序的回調URL。在Google上創建應用時,您可能會指定這一點。 – Gazler

回答

0

您可以檢查Google Auth here的示例。它涵蓋了您需要與gcs進行交互的所有內容。