0

I'm using Omnicontact gem but I have some problem making it works with gmail: I always get "redirect_uri_mismatch" error!

Here's the code of 'config/inizializers/omnicontacts.rb'

  3 require "omnicontacts"
  4
  5 Rails.application.middleware.use OmniContacts::Builder do
  6   importer :gmail, "MySecretId", "MySecretKey", {:redirect_path => "/invites/gmail/contact_callback" }
  7 end

'invites_controller.rb' controller code:

  3     def index
  4         @contacts = request.env['omnicontacts.contacts']
  5         respond_to do |format|
  6             format.html
  7         end
  8     end

Routes.rb code:

  3     get "/invites/:provider/contact_callback" => "invites#index"
  4     get "/contacts/failure" => "invites#failure"
  5     root :to => "invites#index"

Here's the redirects uri of the google application:

https://www.example.com/oauth2callback
https://127.0.0.1:3000/invites/gmail/contact_callback
https://127.0.0.1/invites/gmail/contact_callback

How can I solve this?

ste
  • 3,087
  • 5
  • 38
  • 73

1 Answers1

0

I know this question is kind of old but this is happening because gmail won't allow you to have ip addresses as redirect uris. You will need to add something like this. yourmachine.example.com:3000/invites/gmail/contact_callback And then in your hosts file you will need to add the following line: 192.168.1.2 devmachine yourmachine.example.com Where 192.168.1.X, is your local ip address.

You should now be able to access your local rails application by going to this url:yourmachine.example.com:3000 in your local machine. Google will now accept this redirect_uri as it's a valid hostname and you should be able to get your contacts back.

rii
  • 1,578
  • 1
  • 17
  • 22