Why is Google Oauth returning `invalid redirect_urI` in my Rails app?

前端 未结 7 1782
一生所求
一生所求 2020-12-04 11:32

I\'m adding Google Oauth2 to a Rails app, but have been unable to get past the early stages.

I\'ve set up an app, and defined client ID and secret.But I\'m getting <

7条回答
  •  攒了一身酷
    2020-12-04 12:01

    I was getting the redirect error for my python / tornado app running on ubuntu. Using localhost didn't work as the accepted answer highlighted. Google wants a public domain.

    My solution was to piggyback "example.com" which is public and create a sub domain in my /etc/hosts file. The sub domain would work on my local dev box and google would be happy with the example.com domain. I registering the redirects via the google console and the redirect worked successfully for me.

    I added the following to my /etc/hosts:

    192.168.33.100   devbox  devbox.example.com
    

    In my case the IP was that of my machine. I could also have used 127.0.0.1 instead.

    My Google API console (https://code.google.com/apis/console) set up for a new client ID was:

    • "Application Type: Web Application".
    • Via "Your site or hostname (more options)":
      • In "Authorized Redirect URIs" I entered http://devbox.example.com/
      • In "Authorized JavaScript Origins" I entered http://devbox.example.com/

提交回复
热议问题