我正在为我的一个 Rails 应用程序设置Doorkeeper和OAuth2。我的目标是根据用户的 access_token 允许 api 访问用户,这样只有用户才能看到他们的 'user_show' json。到目前为止,我已经在“oauth2/applications”路线上设置并授权了我的开发和生产应用程序。
我的'/config/initializers/doorkeeper.rb'
Doorkeeper.configure do
# Change the ORM that doorkeeper will use.
# Currently supported options are :active_record, :mongoid2, :mongoid3,
# :mongoid4, :mongo_mapper
orm :active_record
# This block will be called to check whether the resource owner is authenticated or not.
resource_owner_authenticator do
# Put your resource owner authentication logic here.
# Example implementation:
User.find_by_id(session[:current_user_id]) || redirect_to('/')
end
end
我的 '/api/v1/user/controller.rb' 看起来像这样:
class Api::V1::UserController < Api::ApiController
include ActionController::MimeResponds
before_action :doorkeeper_authorize!
def index
user = User.find(doorkeeper_token.resource_owner_id)
respond_with User.all
end
def show
user = User.find(doorkeeper_token.resource_owner_id)
respond_with user
end
end
我试图访问 OAuth 应用程序表以查看正在创建的内容,但我无法在 rails 控制台中访问它。
提前感谢您的洞察力!