Google OAuth token exchange returns invalid_code

后端 未结 2 457
醉酒成梦
醉酒成梦 2021-02-13 14:56

I have been implementing the Google web server OAuth flow, but when I attempted to exchange the authorization code with access token, it always complains \"invalid_code\".

相关标签:
2条回答
  • 2021-02-13 15:28

    I was using http://localhost:8080 as my redirect url since I was just trying out their examples. And my json file contents had this:

    "redirect_uris": [
      "http://localhost:8080"
    ],
    "javascript_origins": [
      "http://localhost:8080"
    ]
    

    In the developer console I had the redirect_uri set to "http://localhost:8080" and I was getting the same error. I changed it to "http://localhost:8080/" and then it started working. (Essentially adding a '/' at the end.)

    Hope this helps!

    0 讨论(0)
  • 2021-02-13 15:33

    The life span of authorization code is only 10 mins,and can only be used one time. So do these checks:

    1. Do you use it 10 min later? If so, use it in 10 mins.
    2. Have you used it before? If so, obtain a new one and then use it.
    3. Is you server time in sync with Google OAuth server's? If not, change your time.
    0 讨论(0)
提交回复
热议问题