我正在使用葡萄和门卫进行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并注意到,班级DoorkeeperForBuilder
和create_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