设计:devise_saml_authenticatable - 未初始化的常量 SamlSessionsController

Devise: devise_saml_authenticatable - uninitialized constant SamlSessionsController

我正在使用 https://github.com/apokalipto/devise_saml_authenticatable 在 Rails 应用程序的 Ruby 中通过 SAML 实现针对 Okta 的登录。

按照上述说明设置示例应用程序后,尝试导航到 /users/saml/log_in

时出现以下错误
ActionController::RoutingError (uninitialized constant SamlSessionsController):

activesupport (5.1.6) lib/active_support/inflector/methods.rb:269:in `const_get'
activesupport (5.1.6) lib/active_support/inflector/methods.rb:269:in `block in constantize'
activesupport (5.1.6) lib/active_support/inflector/methods.rb:267:in `each'
activesupport (5.1.6) lib/active_support/inflector/methods.rb:267:in `inject'
activesupport (5.1.6) lib/active_support/inflector/methods.rb:267:in `constantize'
actionpack (5.1.6) lib/action_dispatch/http/request.rb:85:in `controller_class_for'
actionpack (5.1.6) lib/action_dispatch/http/request.rb:78:in `controller_class'
actionpack (5.1.6) lib/action_dispatch/routing/route_set.rb:43:in `controller'
actionpack (5.1.6) lib/action_dispatch/routing/route_set.rb:29:in `serve'
actionpack (5.1.6) lib/action_dispatch/routing/mapper.rb:16:in `block in <class:Constraints>'
actionpack (5.1.6) lib/action_dispatch/routing/mapper.rb:46:in `serve'
actionpack (5.1.6) lib/action_dispatch/journey/router.rb:50:in `block in serve'

不确定是什么导致了上述错误。我已确保 gem 是 Gemfile 的一部分并已安装。

还有什么我可以研究的吗?

我能够解决这个问题。这是由于我的路线配置错误。导致问题的路由配置如下:

devise_scope :user do
    scope "users", controller: 'saml_sessions' do
      get :new, path: "saml/sign_in", as: :new_user_sso_session
      post :create, path: "saml/auth", as: :user_sso_session
      get :destroy, path: "sign_out", as: :destroy_user_sso_session
      get :metadata, path: "saml/metadata", as: :metadata_user_sso_session
      match :idp_sign_out, path: "saml/idp_sign_out", via: [:get, :post]
    end
  end

然而,正确的配置应该是:

devise_scope :user do
    scope "users", controller: 'devise/saml_sessions' do
      get :new, path: "saml/sign_in", as: :new_user_sso_session
      post :create, path: "saml/auth", as: :user_sso_session
      get :destroy, path: "sign_out", as: :destroy_user_sso_session
      get :metadata, path: "saml/metadata", as: :metadata_user_sso_session
      match :idp_sign_out, path: "saml/idp_sign_out", via: [:get, :post]
    end
  end

注意,控制器,应该是'devise/saml_sessions'。

经过这次修改后,我就可以顺利进行了。