如何同时使用Devise和Doorkeeper宝石?

Jon*_*ark 13 ruby-on-rails devise oauth-2.0

我正在构建一个使用Devise gem进行身份验证的Web应用程序(也使用API​​),我还使用Doorkeeper gem来验证API部分.

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

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

我怎样才能做到这一点?我正在覆盖Devise会话控制器,但我不知道该怎么做.

这是我的代码:

def new
    session[:return_to] = params[:return_to] if params[:return_to]
    resource = build_resource
    clean_up_passwords(resource)
  end

  def create
    resource = warden.authenticate!(auth_options)
    sign_in(resource_name, resource)
    if session[:return_to]
      redirect_to session[:return_to]
      session[:return_to] = nil
    else
      respond_with resource, :location => after_sign_in_path_for(resource)
    end
  end
Run Code Online (Sandbox Code Playgroud)

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

请进一步咨询.

bon*_*iii 11

假设您的资源已user 添加session[:user_return_to] = request.fullpath到resource_owner_authenticator块

例:

resource_owner_authenticator do
  #raise "Please configure doorkeeper resource_owner_authenticator block located in #{__FILE__}"
  # Put your resource owner authentication logic here.
  # Example implementation:
  session[:user_return_to] = request.fullpath
  current_user || redirect_to(login_url)
end
Run Code Online (Sandbox Code Playgroud)