Getting refresh tokens from Google with OAuth.io

前端 未结 1 1538
心在旅途
心在旅途 2020-12-17 02:40

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 offlin

相关标签:
1条回答
  • 2020-12-17 03:15

    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/

    0 讨论(0)
提交回复
热议问题