3

Problem

I'm getting the following error:

"error": {
      "message": "Invalid redirect_uri: Given URL is not allowed by the Application configuration.",
      "type": "OAuthException",
      "code": 191
   }

It is very known and I found many different solutions to adress it and unfortunatelly any of them worked for me.

I'm trying to make it run locally in the localhost:3000, but can't make it work.

My configuration is a common configuration:

config/initializers/devise.rb

config.omniauth :facebook, '396783260390829', 'a504939e60c3410ed1becc44f41d4b94', {client_options: {ssl: {ca_file: Rails.root.join('lib/assets/cacert.pem').to_s}}}

Facebook config:

enter image description here

Routes.rb

devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" }

devise_scope :user do
  get '/users/auth/:provider' => 'users/omniauth_callbacks#passthru'
end

I already tried the following approaches:

Approach 1:

OmniAuth.config.full_host = '`http://localhost:3000/`'

This one was the closest I got, because it redirect me back, but the adress was http://localhost:3000//users/auth/facebook/callbacks?xxx

I already tried without the last slash OmniAuth.config.full_host = 'http://localhost:3000', but then I got the 191.

Approach 2

Normal initializer, without the hack.

Approach 3

Set the domain in the Facebook configuration page.

Approach 4

Set App Domains to localhost

Approach 5

Set the Web Site in Facebook configuration to http://localhost:3000/users/auth/facebook

Approach 6

Tryied with my ip adress instead of localhost and got the same error, but pnot in the failure of OmniauthCallbacksController, but in the graph.facebook.com/oauth/authorize?

redirect_uri=http://localhost:3000/users/auth/facebook/callback

Result for all approaches

In all the cases except the ones I explained inline I got

OAuthException 191

in the failure method of OmniauthCallbackController I created to handle the callback.

Please if you know other alternatives or want to see anything else to try to help me, feel free to ask or answer.


felipeclopes
  • 4,010
  • 2
  • 25
  • 35
  • 1
    You must be following some really old tutorials as the omniauth configuration with devise is done in a completely different way. Take a look at the wiki of the project, if you follow it to the letter you'll get the job done. https://github.com/plataformatec/devise/wiki/OmniAuth%3A-Overview – Ashitaka Nov 09 '12 at 02:09
  • Actually I took my configuration exactly from the wiki you linked, the only difference is OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE that i use to ignore ssl – felipeclopes Nov 09 '12 at 02:12
  • But you have an `omniauth.rb` file! That does not appear on that wiki and you shouldn't need that. – Ashitaka Nov 09 '12 at 02:16
  • If you want to post as an answer I'll accept it. Thank you, it worked. – felipeclopes Nov 09 '12 at 03:13
  • The solution should be posted as an answer, not as part of the question. You can post answers to your own questions and accept them. – Rimian Mar 31 '13 at 16:56

2 Answers2

1

Facebook does not allow the redirect address to be localhost. You must use a real IP address or named address. See answer to similar question: Facebook app - login through omniauth - OAuthException 191

Community
  • 1
  • 1
Saboosh
  • 409
  • 4
  • 7
0

Solution

As mentioned by @AshitakaI had to remove my old and deprecated omniauth.rb, so my final and working configuration is the following one:

config/initializers/devise.rb

In order to make authentication works I copied the cacert to my assets and referenced in the devise.rb

config.omniauth :facebook, 'xxxxxxxxxxxxxxx', 'a504xxxe60cxxxxed1bexxxxf41d4b94', {client_options: {ssl: {ca_file: Rails.root.join('lib/assets/cacert.pem').to_s}}}

Facebook config:

![enter image description here][1]

Link to Facebook auth

/users/auth/facebook

Thank you for the help, this issue took me 5 hours to solve.

felipeclopes
  • 4,010
  • 2
  • 25
  • 35