【发布时间】:2018-01-03 21:14:20
【问题描述】:
在我当前的应用程序中,我有两个门卫范围,user 和 admin。在 doorkeeper documentation 中用于在 API 中设置范围时显示
class Api::V1::ProductsController < Api::V1::ApiController
before_action -> { doorkeeper_authorize! :public }, only: :index
before_action only: [:create, :update, :destroy] do
doorkeeper_authorize! :admin, :write
end
...
end
我不想在每个控制器中都调用门卫,所以在我的 ApplicationController 中我有
module API
module V1
class ApplicationController < ActionController::API
before_action { doorkeeper_authorize! :user, :project }
...
end
end
end
但我不想让:project 访问每个控制器。有没有办法让我在我们的应用程序控制器before_action { doorkeeper_authorize! :user } 中允许user 并在每个控制器的基础上允许project?即:
module API
module V1
class SomeController < ApplicationController
before_action only: [:index, :show] { doorkeeper_authorize! :project }
...
end
end
end
【问题讨论】: