Skip to content

Running Doorkeeper with Devise

Michael Monerau edited this page Jan 25, 2019 · 3 revisions

In case you want to use Doorkeeper with devise The resource_owner_authenticator should be replaced by below block to generate auth_tokens for your client apps

resource_owner_authenticator do |routes|
  # Put your resource owner authentication logic here.
  # If you want to use named routes from your app you need
  # to call them on routes object eg.
  # routes.new_user_session_path
  current_user || warden.authenticate!(:scope => :user)
end

Also, you need to not call authenticate_#{resource_name}! in the authenticate_scope! function. The best way is to redefine yourself the function in your registration controller with:

  def authenticate_scope!
    # send(:"authenticate_#{resource_name}!", force: true)
    self.resource = send(:"current_#{resource_name}")
  end

(It is just commented here as a way of showing what is disabled.)

You also need to define a proper current_resource_owner function, when you use Doorkeeper tokens. To achieve that, define in your Application Controller:

def current_resource_owner
  User.find(doorkeeper_token.resource_owner_id) if doorkeeper_token
end

def current_user
  current_resource_owner
end
Clone this wiki locally