【发布时间】:2014-05-09 22:57:17
【问题描述】:
我正在编写一个带有网页的 API。我想要 Oauth2 登录,这样我就可以在移动设备上保持会话,我已经安装了 GEM 门卫并运行迁移,它是如何在 this site. 上解释的@
我被卡住的地方是 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 块?我如何获得令牌?
【问题讨论】:
标签: ruby-on-rails-4 oauth-2.0 doorkeeper