2015-07-01 97 views
10

我正嘗試使用OAuth.io爲Google提供者獲取使用令牌&刷新令牌。我已選擇脫機訪問OAuth.io中的access_type。使用OAuth.io JS SDK(客戶端)從Google獲取刷新令牌

以下是我沒有收到在響應refresh_token代碼

OAuth.popup("google", {'authorize' : { "approval_prompt" : 'force'}}) 
    .done(function(result) { 
     console.log(result); 
    }) 
    .fail(function (err) { 
     //handle error with err 
     console.log(err); 
    }); 

。我只從響應中獲得access_token。訪問令牌

JSON的反應是:

{ 
     "status": "success", 
     "data": { 
      "access_token": "ya29.pAGQWe3yxxxxxx", 
      "token_type": "Bearer", 
      "expires_in": 3600, 
      "request": { 
       "url": "https://www.googleapis.com", 
       "headers": { 
        "Authorization": "Bearer {{token}}" 
       } 
      }, 
      "id_token": "eyJhbGciOiJSUzIxxxxxxxx" 
     }, 
     "state": "Q9nfocQXJxxxx", 
     "provider": "google" 
    } 

參考

我發現這個鏈接SO Getting refresh tokens from Google with OAuth.io 在這裏,他們解釋瞭如何獲得服務器端刷新令牌。

我想在客戶端JS中獲取刷新令牌。

+0

你能不能從服務器到客戶端通過它發送刷新令牌前端? – winhowes

回答

2

轉到OAuth.io應用的常規設置頁面中,選擇顯示高級選項,然後選擇發送刷新令牌前端

在集成的API中,選擇access_typeoffline。這將同時使用下面的代碼

var oauthOptions = { 'authorize' : { "approval_prompt" : "force" } }; 
    OAuth.popup("google", oauthOptions) 
       .done(function(result) { 
        console.log("Post postProcessing"); 
        console.log(result); 
       }) 
       .fail(function (err) { 
        console.log(err); 
       }); 

enter image description here

-1
  1. 轉到帳戶的安全設置,然後單擊編輯
  2. https://www.google.com/settings/u/1/security
  3. 旁邊的「授權應用程序和網站」。然後點擊「撤銷
  4. 訪問」旁邊的應用程序。您製作的下一個OAuth2請求將會返回一個refresh_token,將會返回

您還可以打開的Oauth玩Here

+0

我已經撤銷對我的應用程序的權限。然後我啓動了OAuth,我沒有收到refresh_token – Valarpirai

0

嘗試更改第一行:

OAuth.popup("google", { 
    'authorize' : { 
    "approval_prompt" : "force", 
    "access_type" : "offline"}}) 

Google's docs描述刷新如何脫機工作令牌。

+0

我試着用access_type:「offline」,在響應中沒有收到refresh_token。 – Valarpirai

+0

您是否可以嘗試使用Firebug或Chrome開發工具運行OAuth請求以查看OAuth.io正在擊中的URL? –

+0

https://oauth.io/auth/google?k=ndXMRv8xxxxxx&d=http://localhost/&opts={"authorize":{"approval_prompt":"force","access_type":"offline"},"state 「:」nBGE8Rv1ufxxxxxxxx「,」state_type「:」client「}這是(解碼)URL Oauth.io JS用於打開彈出窗口 – Valarpirai

相關問題