omn​​iauth回调找不到映射设计

时间:2017-05-25 19:43:21

标签: ruby-on-rails ruby devise activeadmin omniauth

我有rake routes的以下输出:

$ rake routes | grep linkedin
admin_user_linkedin_omniauth_authorize GET|POST   /auth/linkedin(.:format)                    users/omniauth_callbacks#passthru
 admin_user_linkedin_omniauth_callback GET|POST   /auth/linkedin/callback(.:format)           users/omniauth_callbacks#linkedin
      user_linkedin_omniauth_authorize GET|POST   /auth/linkedin(.:format)                    users/omniauth_callbacks#passthru
       user_linkedin_omniauth_callback GET|POST   /auth/linkedin/callback(.:format)           users/omniauth_callbacks#linkedin

文件app/controllers/users/omniauth_callbacks_controller.rb是:

class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
  def linkedin
    @user = User.from_omniauth(env["omniauth.auth"], current_user)
    puts(env["omniauth.auth"])
    if @user.persisted?
      sign_in_and_redirect @user
    else
      session["devise.linkedin_data"] = env["omniauth.auth"]
      session[:user_id]
    end
  end
end

设计初始化程序脚本具有以下内容

config.omniauth_path_prefix = '/auth'

config/routes.rb文件是:

Rails.application.routes.draw do
  devise_config = ActiveAdmin::Devise.config
  devise_config[:controllers][:omniauth_callbacks] = 'users/omniauth_callbacks'
  # Based off the answer at https://stackoverflow.com/a/30270909/1190388
  devise_for :admin_users, {class_name: 'User'}.merge(devise_config)
  ActiveAdmin.routes(self)

  # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
  root to: 'home#index'

  devise_for :users, controllers: {
               :omniauth_callbacks => 'users/omniauth_callbacks'
             }
end

当我前往/auth/linkedin页面时,我会生成正确的回调和所有内容,但是,我收到以下运行时错误:

  

无法找到路径"/auth/linkedin/callback"

的有效映射      

参数:

{"code"=>"SOME_HASH_1", "state"=>"ANOTHER_HASH_2"}

同样的问题可能是什么?

PS:我能找到的最接近的类似问题是Devise omniauthable breaks Omniauth authentication with `Could not find a valid mapping for path`,但在我的案例中没有用。

0 个答案:

没有答案