Skip to content
Benjamin Groessing edited this page Oct 22, 2018 · 7 revisions

Version >= 0.5

Doorkeeper routes accept a few customization options for generating routes in your application:

The basic generated routes are:

# routes.rb
Rails.application.routes.draw do
  use_doorkeeper
end

generates:

GET       /oauth/authorize/native?code
GET       /oauth/authorize
POST      /oauth/authorize
DELETE    /oauth/authorize
POST      /oauth/token
POST      /oauth/revoke
POST      /oauth/introspect
resources /oauth/applications
GET       /oauth/authorized_applications
DELETE    /oauth/authorized_applications/:id
GET       /oauth/token/info

Also you can do some extra customization:

Rails.application.routes.draw do
  # Change 'oauth' scope to custom one
  use_doorkeeper scope: 'scope'

  # Place routes under additional scope
  scope 'auth' do
    use_doorkeeper scope: 'endpoint' do
      # Customize controllers
      controllers authorizations: 'custom_authorizations',
                  tokens: 'custom_authorizations',
                  applications: 'custom_authorizations',
                  token_info: 'custom_authorizations'

      as authorizations: 'custom_auth',
         tokens: 'custom_token',
         token_info: 'custom_token_info'
    end
  end

  # Skip some controllers
  use_doorkeeper do
    skip_controllers :tokens, :applications, :token_info
  end
end

See additional info below:

Changing controllers

You may want to change the controllers to your custom controllers with:

Rails.application.routes.draw do
  use_doorkeeper do
    # it accepts :authorizations, :tokens, :token_info, :applications and :authorized_applications
    controllers :applications => 'custom_applications'
  end
end

You'll need a CustomApplicationsController class in your app/controllers. If you want to extend the default behaviour, just inherit from Doorkeeper::ApplicationsController. For example:

class CustomApplicationsController < Doorkeeper::ApplicationsController
end

Changing aliases

If can change the alias options with as:

Rails.application.routes.draw do
  use_doorkeeper do
    # it accepts :authorizations, :tokens, :token_info, :applications and :authorized_applications
    as :authorizations => 'custom_auth', :tokens => 'custom_token'
  end
end

Skipping controllers

If you want to skip some routes and provide your own routes, use skip_controllers option:

Rails.application.routes.draw do
  use_doorkeeper do
    # it accepts :authorizations, :tokens, :token_info, :applications and :authorized_applications
    skip_controllers :applications, :authorized_applications
  end
end

Namespacing

You can namespace doorkeeper routes just like you do in the usual rails routes:

Rails.application.routes.draw do
  scope 'space' do
    use_doorkeeper
  end
end

This will generate:

GET       /space/oauth/authorize
POST      /space/oauth/authorize
DELETE    /space/oauth/authorize
POST      /space/oauth/token
resources /space/oauth/applications

This also applies to constraints too.

Customizing scope

You can customize doorkeeper default oauth scope:

Rails.application.routes.draw do
  use_doorkeeper :scope => 'oauth2'
end

This will generate:

GET       /oauth2/authorize
POST      /oauth2/authorize
DELETE    /oauth2/authorize
POST      /oauth2/token
resources /oauth2/applications
# ...

Version < 0.5

Doorkeeper versions prior to 0.5 don't provide customization. You're only able to mount all routes into your application routes:

Rails.application.routes.draw do
  mount Doorkeeper::Engine => "/oauth"
  # your routes
end

This will mount the following routes:

GET       /oauth/authorize
POST      /oauth/authorize
DELETE    /oauth/authorize
POST      /oauth/token
resources /oauth/applications
Clone this wiki locally