When authenticating with oAuth and youtube, always get error : invalid_grant on 2nd auth attempt, why?

后端 未结 2 804
独厮守ぢ
独厮守ぢ 2020-12-16 01:36

As of yesterday, my application is able to authenticate with google (youtube) via oAuth 2.0 the first time no problem but the 2nd time (re-authentication, same app + same us

相关标签:
2条回答
  • 2020-12-16 02:19

    I think I may have found the answer here:

    https://groups.google.com/forum/#!searchin/oauth2-dev/invalid_grant/oauth2-dev/eaOa6THER0k/z4eO-taUFxgJ

    The problem was that that the "code" parameter that you need to send needs to be encoded. It will work when you set the approval_prompt to force because the return code contains URL-safe characters. However, this is not the case for the return code upon a second authorization request.

    For me this fixed it, I hope it does for you as well.

    0 讨论(0)
  • 2020-12-16 02:36

    I found a way to fix this (at least for us). When redirecting to the accounts.google.com/o/oauth2/auth url, we had to add both approval_prompt=force and access_type=offline. If one was missing, we got no refresh token.

    This url documents all of the parameters, but says nothing about the refresh token: http://code.google.com/apis/accounts/docs/OAuth2WebServer.html

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