Question

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?

Was it helpful?

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top