ruby-on-rails - 誓言资源看门人还缺少什么?

标签 ruby-on-rails doorkeeper

我的路由文件中有 use_doorkeeper 。当我访问 http://localhost:3021/oauth/applications 时,我得到:

Access to localhost was denied You don't have authorization to view this page.
HTTP ERROR 403

我也无法在 http://localhost:3021/oauth/applications/new 中创建新客户端。

缺少什么?

这是我的路线文件

Rails.application.routes.draw do

  use_doorkeeper

end

这是我的 dookeeper 初始化程序

Doorkeeper.configure do
  # Change the ORM that doorkeeper will use (needs plugins)
  orm :active_record

  # This block will be called to check whether the resource owner is authenticated or not.
  resource_owner_authenticator do
    #raise "Please configure doorkeeper resource_owner_authenticator block located in #{__FILE__}"
    # Put your resource owner authentication logic here.
    # Example implementation:
    User.find_by_id(session[:user_id]) || redirect_to(new_user_session_url)
    #current_user || User.authenticate!(:scope => :user)

  end
end

最佳答案

检查控制台中的日志输出。 如果您看到以下几行,则问题可能出在您的doorkeeper.rb

Access to admin panel is forbidden due to Doorkeeper.configure.admin_authenticator being unconfigured.
Filter chain halted as :authenticate_admin! rendered or redirected
Completed 403 Forbidden in 2ms (ActiveRecord: 0.0ms)

您必须取消注释此部分:

  # admin_authenticator do
  #   # Put your admin authentication logic here.
  #   # Example implementation:
  #
  # if current_user
  #  head :forbidden unless current_user.admin?
  #   else
  #     redirect_to sign_in_url
  #   end
  # end

如果您没有设置管理员角色,请删除 head :forbidden except current_user.admin?

并且可能会更改重定向网址

关于ruby-on-rails - 誓言资源看门人还缺少什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54300605/

相关文章:

ruby-on-rails - Rails 将 secret 转换为凭据

ruby-on-rails - 包含/使用 "partial view"时的最佳实践?

ruby-on-rails - 多个模型的 Doorkeeper 资源所有者凭证流

ruby-on-rails - 存储星期几和时间?

ruby-on-rails - Rails 2.3.14:如何序列化 ActionController::Request 对象?

ruby-on-rails - Rails,如何通过created_at 对事件记录数组进行排序

ruby-on-rails - 如何手动撤销 Doorkeeper token ?

ruby-on-rails-4 - Doorkeeper::AuthorizationsController#create 无法验证 CSRF token 的真实性

ruby-on-rails - 是否可以将门禁与操作电缆一起使用?