ruby-on-rails – 如何使用Devise和Doorkeeper宝石?

前端之家收集整理的这篇文章主要介绍了ruby-on-rails – 如何使用Devise和Doorkeeper宝石?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在构建一个使用Devise gem进行身份验证的Web应用程序(还有一个API),并且还使用Doorkeeper gem进行API部分的身份验证.

问题是现在,当我转到接收Oauth2代码(和登录)的URL时,我被重定向到Web应用程序而不是客户端回调URL.

我需要做的是在正常登录重定向到Web应用程序,并在使用Oauth时重定向到回调URL.

我该怎么做?我覆盖了Devise会话控制器,但我不知道该怎么做.

这是我的代码

  1. def new
  2. session[:return_to] = params[:return_to] if params[:return_to]
  3. resource = build_resource
  4. clean_up_passwords(resource)
  5. end
  6.  
  7. def create
  8. resource = warden.authenticate!(auth_options)
  9. sign_in(resource_name,resource)
  10. if session[:return_to]
  11. redirect_to session[:return_to]
  12. session[:return_to] = nil
  13. else
  14. respond_with resource,:location => after_sign_in_path_for(resource)
  15. end
  16. end

问题是,Devise似乎忽略了我的重定向逻辑.

请进一步建议.

解决方法

假设你的资源是用户添加会话[:user_return_to] = request.fullpath到resource_owner_authenticator块

例:

  1. resource_owner_authenticator do
  2. #raise "Please configure doorkeeper resource_owner_authenticator block located in #{__FILE__}"
  3. # Put your resource owner authentication logic here.
  4. # Example implementation:
  5. session[:user_return_to] = request.fullpath
  6. current_user || redirect_to(login_url)
  7. end

猜你在找的Ruby相关文章