Ruby on rails Desive Omniauth Facebook可以在本地主机上运行,但不能在Heroku上运行

Ruby on rails Desive Omniauth Facebook可以在本地主机上运行,但不能在Heroku上运行,ruby-on-rails,facebook,devise,omniauth,Ruby On Rails,Facebook,Devise,Omniauth,我有一个使用Heroku的Rails 5.1应用程序 我正在尝试将Desive与Omniauth Facebook一起使用。问题是,我在localhost:3000上运行得很好,但在尝试注册或登录生产时出现了一个错误 根据Heroku日志,问题似乎在于回调: 2018-01-21T22:00:32.492550+00:00 heroku[router]: at=info method=GET path="/auth/auth/facebook/callback? code=AQC1IE8y6N

我有一个使用Heroku的Rails 5.1应用程序

我正在尝试将Desive与Omniauth Facebook一起使用。问题是,我在localhost:3000上运行得很好,但在尝试注册或登录生产时出现了一个错误

根据Heroku日志,问题似乎在于回调:

2018-01-21T22:00:32.492550+00:00 heroku[router]: at=info method=GET 
path="/auth/auth/facebook/callback?
code=AQC1IE8y6NsiIlFWhCnG_bdH4MoG7XFkOcGRhl4qUAr-
hZ3e6nxTHJR6mothkNKhlFh0NzueLZRaPEtkKBsHb-
PEWNSou5ZAfCwV_M845DT7WKtdwcU6R84c15a0HVys-
9ml0PKI2Wljgu8CzOBz4uhYdPMlkm6AFAvmR1ZCkJ7UGL9Qpm23VQWe-xJ7uv0mtzc9zOIROQT8fQAUW6WUTbHnl-
SywyS0omFU-XiAq2KaXZpcolO7Hnkk0NEgcssZHuBeO6IBZisQchCjPGXi6VdxFmLFgvyxuxrVlSL79ELELqWxXPdpIjn
GVlx2aIpBV12Gqkm8ocI0JhjFbmoD9CUGpd4v4w5kbdlblN3106bZvw&state=ef00f5f6519d9a51e0d9
4846c6c6739bfea76d3e44b3ec69" 
host=www.gourmetcoffee.london request_id=b177986b-
b27c-450e-9950-4af8ef9359af fwd="2a02:c7d:3dc:8e00:91b:3d48:a2e1:4c1d,162.158.154.234" 
dyno=web.1 connect=0ms service=931ms status=500 bytes=1733 protocol=https
我已经用
FACEBOOK\u APP\u ID
FACEBOOK\u APP\u SECRET
更新了我的Heroku配置变量。它们也存储在
config/application.yml

宝石

#User authentication
gem 'devise'
gem 'omniauth'
gem 'omniauth-facebook', '~>4.0'
user_facebook_omniauth_authorize GET|POST /users/auth/facebook(.:format)                          users/omniauth_callbacks#passthru
 user_facebook_omniauth_callback GET|POST /users/auth/facebook/callback(.:format)                 users/omniauth_callbacks#facebook
routes.rb

#authentication
  devise_for :users, path: "auth", controllers: {
    sessions: 'users/sessions',
    registrations: 'users/registrations',
    unlocks: 'users/unlocks',
    omniauth_callbacks: 'users/omniauth_callbacks'
  }
  devise_scope :user do
    delete 'sign_out', :to => 'devise/sessions#destroy', :as => :destroy_fb_user_session
  end
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController

  def facebook
  # You need to implement the method below in your model (e.g. app/models/user.rb)
  @user = User.from_omniauth(request.env["omniauth.auth"])

  #When a valid user is found, they can be signed in with one of two Devise methods: sign_in or sign_in_and_redirect.

  if @user.persisted?
    sign_in_and_redirect @user#, :event => :authentication this will throw if @user is not activated
    set_flash_message(:notice, :success, :kind => "Facebook") if is_navigational_format?
  else
    session["devise.facebook_data"] = request.env["omniauth.auth"]
    redirect_to new_user_registration_url
  end
end

def failure
  redirect_to root_path
end


  protected

  # The path used when OmniAuth fails
  def after_omniauth_failure_path_for(scope)
    super(scope)
   end
end
  config.omniauth :facebook, ENV['FACEBOOK_APP_ID'], ENV['FACEBOOK_APP_SECRET'], scope: "email", info_fields: 'email, first_name, last_name'
omniauth\u回调\u controller.rb

#authentication
  devise_for :users, path: "auth", controllers: {
    sessions: 'users/sessions',
    registrations: 'users/registrations',
    unlocks: 'users/unlocks',
    omniauth_callbacks: 'users/omniauth_callbacks'
  }
  devise_scope :user do
    delete 'sign_out', :to => 'devise/sessions#destroy', :as => :destroy_fb_user_session
  end
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController

  def facebook
  # You need to implement the method below in your model (e.g. app/models/user.rb)
  @user = User.from_omniauth(request.env["omniauth.auth"])

  #When a valid user is found, they can be signed in with one of two Devise methods: sign_in or sign_in_and_redirect.

  if @user.persisted?
    sign_in_and_redirect @user#, :event => :authentication this will throw if @user is not activated
    set_flash_message(:notice, :success, :kind => "Facebook") if is_navigational_format?
  else
    session["devise.facebook_data"] = request.env["omniauth.auth"]
    redirect_to new_user_registration_url
  end
end

def failure
  redirect_to root_path
end


  protected

  # The path used when OmniAuth fails
  def after_omniauth_failure_path_for(scope)
    super(scope)
   end
end
  config.omniauth :facebook, ENV['FACEBOOK_APP_ID'], ENV['FACEBOOK_APP_SECRET'], scope: "email", info_fields: 'email, first_name, last_name'
有效的OAuth重定向URI

#User authentication
gem 'devise'
gem 'omniauth'
gem 'omniauth-facebook', '~>4.0'
user_facebook_omniauth_authorize GET|POST /users/auth/facebook(.:format)                          users/omniauth_callbacks#passthru
 user_facebook_omniauth_callback GET|POST /users/auth/facebook/callback(.:format)                 users/omniauth_callbacks#facebook
http://localhost:3000/
https://www.gourmetcoffee.london

更新 我已经修改了
routes.rb
删除
路径:“auth”

#authentication
  devise_for :users, controllers: {
    sessions: 'users/sessions',
    registrations: 'users/registrations',
    unlocks: 'users/unlocks',
    omniauth_callbacks: 'users/omniauth_callbacks'
  }
但仍然会出现错误。现在似乎是状态=304,
未修改

2018-01-22T08:21:48.156847+00:00 heroku[router]: at=info method=GET path="/assets/loginWithFacebook" host=www.gourmetcoffee.london request_id=243e2fd1-42c8-4ae1-8bbb-f398e6e9e02c fwd="2a02:c7d:3dc:8e00:a0a1:a430:c07:150,141.101.107.208" dyno=web.1 connect=0ms service=2ms status=304 bytes=322 protocol=https
bundle exec rake路由

#User authentication
gem 'devise'
gem 'omniauth'
gem 'omniauth-facebook', '~>4.0'
user_facebook_omniauth_authorize GET|POST /users/auth/facebook(.:format)                          users/omniauth_callbacks#passthru
 user_facebook_omniauth_callback GET|POST /users/auth/facebook/callback(.:format)                 users/omniauth_callbacks#facebook
我以前没有使用过像这样的多个“有效OAuth重定向URI”。然而,我曾经面临同样的问题。我通过用我的在线域替换localhost解决了这个问题。让我们再次检查此URL。 替换:

作者:


您是否尝试过在生产环境或类似环境中本地运行它?您可以使用ngrok.io或localtunnel.me之类的工具在本地进行映射。然后,您可以通过更改
config来进一步显示错误。请考虑将我的facebook中的所有请求\u local
更改为true(然后在生产时将其更改回false)有效Oauth重定向URI I have full path()。我还注意到,在您的日志中,路径auth重复:“/auth/auth/facebook/callback”@Pablo我注意到
auth/auth
在哪里设置的。我一直在寻找它。我想路径:“auth”在您的路线是问题。谢谢@Pablo我更新了我的路线,但仍然不工作。