用门卫2.0.1认证葡萄0.10.1

时间:2015-01-07 16:58:43

标签: ruby-on-rails ruby oauth-2.0 grape doorkeeper

我正在使用葡萄和门卫进行OAuth2身份验证。现在,我想从葡萄0.8升级到葡萄0.10.1,门卫升级到2.0.1。不幸的是,我遇到了一些问题。之前,我可以使用葡萄门卫轻松地将门卫整合到葡萄https://github.com/fuCtor/grape-doorkeeper

但升级后,我收到了一些错误,例如uninitialized constant Doorkeeper::DoorkeeperForBuilder (NameError),而doorkeeper_for助手似乎也从门卫中删除了,并被before_action :doorkeeper_authorize!取代(请参阅https://github.com/doorkeeper-gem/doorkeeper/blob/master/CHANGELOG.md#backward-incompatible-changes)。

Graset文档告诉我们,https://github.com/intridea/grape#register-custom-middleware-for-authentication我们可以使用rack-oauth2进行OAuth2身份验证,但据我所知,这缺少了守门员提供的轻松的rails集成,对吧?

所以现在,我有点困惑,如何将门卫2.0.1融入葡萄0.10.1。我已经阅读了一些教程,但是他们针对这个宝石定位了旧版本。所以,任何帮助都表示赞赏!

更新

我深入研究了GrapeDoorkeeper gem,发现了以下几行(https://github.com/fuCtor/grape-doorkeeper/blob/master/lib/grape-doorkeeper/oauth2.rb#L64):

module OAuth2 def doorkeeper_for *args doorkeeper_for = Doorkeeper::DoorkeeperForBuilder.create_doorkeeper_for(*args) use GrapeDoorkeeper::Middleware, doorkeeper: doorkeeper_for end end

然后我查看了门卫2.0.1并注意到,班级DoorkeeperForBuildercreate_doorkeeper_for方法已经消失。我也找不到替代品或其他方式来做到这一点。对我来说,看起来Doorkeeper::DoorkeeperForBuilder.create_doorkeeper_for返回了葡萄使用的中间件。那么,如何用新门卫做到这一点?

另一个问题是,如果这条线仍然适用于门卫2:https://github.com/fuCtor/grape-doorkeeper/blob/master/lib/grape-doorkeeper/oauth2.rb#L73

Grape::API.extend GrapeDoorkeeper::OAuth2

1 个答案:

答案 0 :(得分:0)

我最近从葡萄门卫转移到wine_bouncer 它适用于ruby 2.2.0和rails 4.2.0,门卫2.0.1和葡萄0.10.1。