注册申请
Doorkeeper 带有集成的控制器/视图来管理 oauth 应用程序、请求访问令牌和授权。
如果您正确安装和配置了门禁,这些路由将在您的 rails 应用程序中定义:
GET /oauth/authorize/:code
GET /oauth/authorize
POST /oauth/authorize
DELETE /oauth/authorize
POST /oauth/token
POST /oauth/revoke
resources /oauth/applications
GET /oauth/authorized_applications
DELETE /oauth/authorized_applications/:id
GET /oauth/token/info
(见https://github.com/doorkeeper-gem/doorkeeper#routes)
当您转到/oauth/applications 时,您可以添加或删除 oauth 应用程序。这可能有助于解决您的问题
创建其他开发者可以注册他们的应用程序的页面,获取他们的密钥
但是,这些是为后端或快速设置目的而设计的。不建议在生产中使用它。您可以根据这些创建控制器/视图。
如果您想了解有关自定义这些控制器/视图的更多信息,请查看以下链接:
设置您的 API
如果您不使用Rails API mode,我建议您使用grape gem,它是一个在Ruby 中构建API 的框架。然后,您可以将 Grape::API 应用程序挂载到 Rails 应用程序的路由。
然后,当用户注册他们的应用程序时,他们将要求为他们自己的应用程序的每个用户授予访问权限(授权码)。 /oauth/authorize 路线就是这样。他们将使用 OAuth2 客户端正确构建 authorize_url 并设置他们的应用程序。
所有这些流程都符合 OAuth2 框架 (RFC 6749)。但正如你所说;你读过它,所以你应该明白幕后发生了什么。
您所要做的就是提供您的 API 端点:
# in your API class that extends Grape::API
post 'orders/:id/buy' do
# authorize a specific scope, this is just an example,
# this might not suit your app design
doorkeeper_authorize! :buy_order
# you can get the resource owner id with and other token infos,
# or put that in a helper method
current_user = User.find(doorkeeper_token.resource_owner_id)
# buy order logic goes here...
end
post 'orders/:id/sell' do
doorkeeper_authorize! :sell_order
current_user = User.find(doorkeeper_token.resource_owner_id)
# sell order logic goes here...
end
希望能帮到你!