Search code examples
ruby-on-railssorcerydoorkeeper

Integrating Doorkeeper and Sorcery


I am having trouble with setting up doorkeeper to authenticate using Sorcery..

Sorcery provides a login method via the controller but it doesn't work to use it in the Doorkeeper.rb file.

Doorkeeper.rb

Doorkeeper.configure do
  ...
  resource_owner_from_credentials do |routes|
    login(params[:username], params[:password])
  end

Gives this result:

NoMethodError (undefined method `login' for #<Doorkeeper::TokensController:0x0000000209ee38>):

How can I do this?


Solution

  • Anthonator on github answered my question here but for posterity's sake this is what he said.

    This is what I have in initializers/doorkeeper.rb

    resource_owner_from_credentials do |routes|
      User.authenticate(params[:username], params[:password])
    end
    

    I also have this is my API controller

    private
    def current_user
      @current_user ||= User.find_by_id(doorkeeper_token.resource_owner_id) if doorkeeper_token
    end