我是Ruby On Rails中api开发的新手。在rails应用程序中我设计了身份验证,我也想在apis上使用门卫进行OAuth2登录。我不知道如何实现Api以及如何使用门卫。任何人都可以用我需要遵循的步骤来解释它吗?
答案 0 :(得分:1)
要实现api,我个人喜欢使用grape,按照自述文件,您将立即启动并运行:)
要将葡萄与门卫融为一体,您可以使用wine_bouncer或grape-doorkeeper。
现在取决于谁消耗你的api,门卫附带4 authorization grants,我建议你阅读不同的授权类型及其用法,你也可以阅读这篇oauth2 simplified文章。
要让门卫与设计一起玩,您需要修改门卫初始化器,如下所示:
当您执行授权或暗示授权请求时,通常会调用resource_owner_authenticator
块:
resource_owner_authenticator do |routes|
# Put your resource owner authentication logic here.
# If you want to use named routes from your app you need
# to call them on routes object eg.
# routes.new_user_session_path
current_user || warden.authenticate!(:scope => :user)
end
您可以在门卫维基上查看example apps。
密码授权使用resource_owner_from_credentials
块,根据维基,您可以将其配置如下:
resource_owner_from_credentials do |routes|
request.params[:user] = {:email => request.params[:username], :password => request.params[:password]}
request.env["devise.allow_params_authentication"] = true
request.env["warden"].authenticate!(:scope => :user)
end
可能对您有所帮助的一些资源:
希望有所帮助