Getting refresh tokens from Google with OAuth.io

寵の児 提交于 2019-11-27 22:32:59

问题


I am trying to get access tokens from OAuth.io for any Google based provider however whenever I authenticate I get an access_token but no refresh_token. I have chosen offline for the access_type but still no joy.

I have tried looking through the documentation for a solution but it barely covers anything related to the refresh token.


回答1:


To get the refresh token from Google, you need 2 things:

  • The offline option cf https://developers.google.com/accounts/docs/OAuth2WebServer

    "A token that may be used to obtain a new access token. Refresh tokens are valid until the user revokes access. This field is only present if access_type=offline is included in the authorization code request."

  • The option approval_prompt set to "force" cf https://developers.google.com/accounts/docs/OAuth2WebServer

    "Important: When your application receives a refresh token, it is important to store that refresh token for future use. If your application loses the refresh token, it will have to re-prompt the user for consent before obtaining another refresh token. If you need to re-prompt the user for consent, include the approval_prompt parameter in the authorization code request, and set the value to force."

so your script should look something like

OAuth.popup('google', {
   authorize: {
      approval_prompt: 'force'
   }
}).then(function(google) {
   console.log(google.refresh_token)
   //send the refresh token to your server
})

If you are working client-side (Javascript / iOS / Android / Phonegap), you may also need to activate the following option: Send refresh token to front-end in the OAuth.io dashboard > General > advanced option to allow your client side SDK to retrieve the refresh token

https://jsfiddle.net/Lqyc5jpw/



来源:https://stackoverflow.com/questions/23759138/getting-refresh-tokens-from-google-with-oauth-io

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!