Search code examples
ruby-on-railsoauth-2.0ruby-on-rails-4.2doorkeeper

How to protect Doorkeeper route in Rails?


I'm using the Doorkeeper gem in a Rails 4.X app. Is there a way to protect the route for managing Oauth applications?

For example, I'd like this URL http://localhost:3000/oauth/applications to be available to the Devise users that are flagged as admins.

My current routes.rb looks like this.

Rails.application.routes.draw do
 mount RailsAdmin::Engine => '/admin', as: 'rails_admin'

 use_doorkeeper
 devise_for :users

Thanks for you help in advance.


Solution

  • Seems Doorkeeper can handle in it's initializer. Just add this and it works.

     admin_authenticator do
       redirect_to new_user_session_url unless current_user && current_user.admin?
     end