[英]API and Application authentication using Devise, Doorkeeper and OAuth2 token
[英]oAuth2 login on the api for web app in ruby on rails using doorkeeper with the help of devise
我是Ruby On Rails中的api開發的新手。 在Rails應用程序中,我設計了用於身份驗證的程序,我還想使用Doorkeeper在api上進行OAuth2登錄。 我不知道如何實現Api以及如何使用網守。 誰能解釋一下實現此步驟需要遵循的步驟?
要實現我個人喜歡使用grape的 api,通過遵循自述文件,您將立即啟動並運行:)
要將葡萄與門衛集成,可以使用wine_bouncer或grape- doorkeeper 。
現在,取決於誰使用了您的api,doorkeeper附帶了4個授權授權 ,我非常建議您閱讀不同的授權類型及其用法,您也可以閱讀此oauth2簡化的文章。
為了使門衛可以隨心所欲地玩游戲,您需要按以下方式修改門衛初始化程序:
當您執行授權或隱式授予請求時,通常會調用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
您可以在門衛Wiki上查看示例應用程序 。
密碼授予改為使用resource_owner_from_credentials
塊,根據Wiki,您可以按以下方式對其進行配置:
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
一些可以幫助您的資源:
希望能幫助到你
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.