我正在用网页编写一个 API。我想要 Oauth2 登录,这样我就可以从移动设备保持会话,我已经安装了 GEM 门卫并按照本网站的说明运行迁移。
我被卡住的地方是 resource_owner_from_credentials 部分,因为我有一个用户模型,它具有由 rails 的 has_secure_password 助手提供的身份验证方法。这就是我的 /config/initializers/doorkeeper.rb 文件的样子
Doorkeeper.configure do
# Change the ORM that doorkeeper will use.
# Currently supported options are :active_record, :mongoid2, :mongoid3, :mongo_mapper
orm :active_record
# This block will be called to check whether the resource owner is authenticated or not.
resource_owner_from_credentials do
User.find_by_email(params[:email]).authenticate(params[:password])
end
##lots of comments
end
什么时候去
localhost:3000/oauth/authorize
我明白了:
config/initializers/doorkeeper.rb:8:in `block (2 levels) in <top (required)>'
然后我尝试了:
http://127.0.0.1:3000/oauth/authorize?email=puca@gmail.com&password=porche
和相同的
我在做什么错?我应该如何配置source_owner_authenticator 块?我如何获得令牌?