Search code examples
ruby-on-railsrubydoorkeeper

Doorkeeper Authentication Correct Syntax


In Doorkeeper.rb, there is a authentication block. I need to fit this logic in there, but I'm not sure how to write it since Ruby' syntax is still new to me.

Either the person is logged in and they are the current_user or the following logic below that is performed.

resource_owner_authenticator do

   current_user ||

   session[:after_login_redirect_to] = request.fullpath
   session[:oauth_for_client_id] = params[:client_id]
   redirect_to('/connect')   

end

Solution

  • You need a begin/end block around the 2nd section. You want the authenticator to return current_user if it exists, otherwise do all the other stuff.

    resource_owner_authenticator do
      current_user || begin
        session[:after_login_redirect_to] = request.fullpath
        session[:oauth_for_client_id] = params[:client_id]
        redirect_to('/connect')
      end
    end