在Rails 3.1中使用门卫的路由问题

时间:2013-10-28 06:25:44

标签: ruby-on-rails oauth doorkeeper

我正在尝试使用门卫(https://github.com/applicake/doorkeeper/)来设置一个简单的OAuth提供程序,但在重命名路由方面存在严重问题。

我正在尝试将我的基本门卫路线设置为'/ oauth2 / v1'而不是预先滚动的'/ oauth'路线。

阅读wiki(https://github.com/applicake/doorkeeper/wiki/Customizing-routes)似乎我需要做的就是修改

Rails.application.routes.draw do
  use_doorkeeper
end

Rails.application.routes.draw do
  use_doorkeeper :scope => 'oauth2/v1'
end

或者命名空间use_doorkeeper到'oauth2'然后提供'v1'的范围。不幸的是,没有任我无法让门卫使用任何其他范围。

wiki本身似乎已经过时了,因为Rails不再在routes.rb中使用那种构造,所以我实际上想要改变的代码看起来更像是这样:

DoorkeeperProvider::Application.routes.draw do
  scope 'oauth2' do
    use_doorkeeper :scope => 'v1'
  end
  ...
end

但是,似乎没有什么能够改变范围。

这是rake路线的输出:

      oauth_authorization GET    /oauth2/oauth/authorize(.:format)                   {:action=>"new", :controller=>"doorkeeper/authorizations"}
      oauth_authorization POST   /oauth2/oauth/authorize(.:format)                   {:action=>"create", :controller=>"doorkeeper/authorizations"}
      oauth_authorization DELETE /oauth2/oauth/authorize(.:format)                   {:action=>"destroy", :controller=>"doorkeeper/authorizations"}
              oauth_token POST   /oauth2/oauth/token(.:format)                       {:action=>"create", :controller=>"doorkeeper/tokens"}
       oauth_applications GET    /oauth2/oauth/applications(.:format)                {:action=>"index", :controller=>"doorkeeper/applications"}
                          POST   /oauth2/oauth/applications(.:format)                {:action=>"create", :controller=>"doorkeeper/applications"}
    new_oauth_application GET    /oauth2/oauth/applications/new(.:format)            {:action=>"new", :controller=>"doorkeeper/applications"}
       edit_oauth_application GET    /oauth2/oauth/applications/:id/edit(.:format)       {:action=>"edit", :controller=>"doorkeeper/applications"}
        oauth_application GET    /oauth2/oauth/applications/:id(.:format)            {:action=>"show", :controller=>"doorkeeper/applications"}
                          PUT    /oauth2/oauth/applications/:id(.:format)            {:action=>"update", :controller=>"doorkeeper/applications"}
                          DELETE /oauth2/oauth/applications/:id(.:format)            {:action=>"destroy", :controller=>"doorkeeper/applications"}
oauth_authorized_applications GET    /oauth2/oauth/authorized_applications(.:format)     {:action=>"index", :controller=>"doorkeeper/authorized_applications"}
 oauth_authorized_application DELETE /oauth2/oauth/authorized_applications/:id(.:format) {:action=>"destroy", :controller=>"doorkeeper/authorized_applications"}
         oauth_token_info GET    /oauth2/oauth/token/info(.:format)                  {:action=>"show", :controller=>"doorkeeper/token_info"}

看起来好像忽略了use_doorkeeper的:scope param。

此时的任何提示都将非常受欢迎。

1 个答案:

答案 0 :(得分:1)

所以看起来你遇到了最近修复过的问题。请参阅此处的提交 - https://github.com/applicake/doorkeeper/commit/a12f9eacaa9714a0681b42f0685e491e296d6560

你在运行什么版本?从理论上讲,这应该在0.7.3中修正。

我尝试使用Github上的应用程序/门卫的门卫主分支。这应该可以解决这个问题。