2015-07-01 34 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

相关问题