OmniAuth + Devise - Facebook provider - OAuthException 191

我们两清 提交于 2019-12-10 19:37:31

问题


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:

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.



回答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




回答2:


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.



来源:https://stackoverflow.com/questions/13301011/omniauth-devise-facebook-provider-oauthexception-191

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!