doorkeeper: rails generate doorkeeper:install failing due to missing configuration

While trying to install doorkeeper 4.2.6 into an existing Rails 5.0.1 application, I ran into the following problem:

$ rails generate doorkeeper:install
~/.rvm/gems/ruby-2.3.3@clear_value_plus/gems/doorkeeper-4.2.6/lib/doorkeeper/config.rb:18:in `configuration': Configuration for doorkeeper missing. Do you have doorkeeper initializer? (Doorkeeper::MissingConfiguration)
	from ~/.rvm/gems/ruby-2.3.3@clear_value_plus/gems/doorkeeper-4.2.6/app/controllers/doorkeeper/application_controller.rb:3:in `<module:Doorkeeper>'
	from ~/.rvm/gems/ruby-2.3.3@clear_value_plus/gems/doorkeeper-4.2.6/app/controllers/doorkeeper/application_controller.rb:1:in `<top (required)>'
	from ~/.rvm/gems/ruby-2.3.3@clear_value_plus/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:477:in `load'
	from ~/.rvm/gems/ruby-2.3.3@clear_value_plus/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:477:in `block in load_file'
	from ~/.rvm/gems/ruby-2.3.3@clear_value_plus/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:662:in `new_constants_in'
	from ~/.rvm/gems/ruby-2.3.3@clear_value_plus/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:476:in `load_file'

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 24 (8 by maintainers)

Most upvoted comments

Under Rails 7, I had to comment the following line of config/environment.rb for the setup to work

Rails.application.initialize!

I was facing the exact issue, and found the solution.

It could fail if you have config.eager_load = true in config/environments/development.rb

If you closely look at the stack-trace of error below, it’s clear that doorkeeper/application_controller is being called by eager_load! in engine.rb. So, I went to config/environments/developement.rb and set config.eager_load = false, and then rails g doorkeeper:install worked smoothly.

I think some gem or initializer is doing something that calls Doorkeeper before it initialized

Thanks @nbulaj for the subtle hint.

/home/prvithani/.rvm/gems/ruby-2.4.2/bundler/gems/doorkeeper-a7f850ac26dd/lib/doorkeeper/config.rb:18:in `configuration': Configuration for doorkeeper missing. Do you have doorkeeper initializer? (Doorkeeper::MissingConfiguration)
	from /home/prvithani/.rvm/gems/ruby-2.4.2/bundler/gems/doorkeeper-a7f850ac26dd/app/controllers/doorkeeper/application_controller.rb:3:in `<module:Doorkeeper>'
	from /home/prvithani/.rvm/gems/ruby-2.4.2/bundler/gems/doorkeeper-a7f850ac26dd/app/controllers/doorkeeper/application_controller.rb:1:in `<top (required)>'
	from /home/prvithani/.rvm/gems/ruby-2.4.2/gems/activesupport-5.1.5/lib/active_support/dependencies.rb:477:in `load'
	from /home/prvithani/.rvm/gems/ruby-2.4.2/gems/activesupport-5.1.5/lib/active_support/dependencies.rb:477:in `block in load_file'
	from /home/prvithani/.rvm/gems/ruby-2.4.2/gems/activesupport-5.1.5/lib/active_support/dependencies.rb:662:in `new_constants_in'
	from /home/prvithani/.rvm/gems/ruby-2.4.2/gems/activesupport-5.1.5/lib/active_support/dependencies.rb:476:in `load_file'
	from /home/prvithani/.rvm/gems/ruby-2.4.2/gems/activesupport-5.1.5/lib/active_support/dependencies.rb:374:in `block in require_or_load'
	from /home/prvithani/.rvm/gems/ruby-2.4.2/gems/activesupport-5.1.5/lib/active_support/dependencies.rb:36:in `block in load_interlock'
	from /home/prvithani/.rvm/gems/ruby-2.4.2/gems/activesupport-5.1.5/lib/active_support/dependencies/interlock.rb:12:in `block in loading'
	from /home/prvithani/.rvm/gems/ruby-2.4.2/gems/activesupport-5.1.5/lib/active_support/concurrency/share_lock.rb:149:in `exclusive'
	from /home/prvithani/.rvm/gems/ruby-2.4.2/gems/activesupport-5.1.5/lib/active_support/dependencies/interlock.rb:11:in `loading'
	from /home/prvithani/.rvm/gems/ruby-2.4.2/gems/activesupport-5.1.5/lib/active_support/dependencies.rb:36:in `load_interlock'
	from /home/prvithani/.rvm/gems/ruby-2.4.2/gems/activesupport-5.1.5/lib/active_support/dependencies.rb:357:in `require_or_load'
	from /home/prvithani/.rvm/gems/ruby-2.4.2/gems/activesupport-5.1.5/lib/active_support/dependencies.rb:335:in `depend_on'
	from /home/prvithani/.rvm/gems/ruby-2.4.2/gems/activesupport-5.1.5/lib/active_support/dependencies.rb:251:in `require_dependency'
	from /home/prvithani/.rvm/gems/ruby-2.4.2/gems/railties-5.1.5/lib/rails/engine.rb:476:in `block (2 levels) in eager_load!'
	from /home/prvithani/.rvm/gems/ruby-2.4.2/gems/railties-5.1.5/lib/rails/engine.rb:475:in `each'
	from /home/prvithani/.rvm/gems/ruby-2.4.2/gems/railties-5.1.5/lib/rails/engine.rb:475:in `block in eager_load!'
	from /home/prvithani/.rvm/gems/ruby-2.4.2/gems/railties-5.1.5/lib/rails/engine.rb:473:in `each'
	from /home/prvithani/.rvm/gems/ruby-2.4.2/gems/railties-5.1.5/lib/rails/engine.rb:473:in `eager_load!'
	from /home/prvithani/.rvm/gems/ruby-2.4.2/gems/railties-5.1.5/lib/rails/engine.rb:354:in `eager_load!'
	from /home/prvithani/.rvm/gems/ruby-2.4.2/gems/railties-5.1.5/lib/rails/application/finisher.rb:67:in `each'
	from /home/prvithani/.rvm/gems/ruby-2.4.2/gems/railties-5.1.5/lib/rails/application/finisher.rb:67:in `block in <module:Finisher>'
	from /home/prvithani/.rvm/gems/ruby-2.4.2/gems/railties-5.1.5/lib/rails/initializable.rb:30:in `instance_exec'
	from /home/prvithani/.rvm/gems/ruby-2.4.2/gems/railties-5.1.5/lib/rails/initializable.rb:30:in `run'
	from /home/prvithani/.rvm/gems/ruby-2.4.2/gems/railties-5.1.5/lib/rails/initializable.rb:59:in `block in run_initializers'
	from /home/prvithani/.rvm/rubies/ruby-2.4.2/lib/ruby/2.4.0/tsort.rb:228:in `block in tsort_each'
	from /home/prvithani/.rvm/rubies/ruby-2.4.2/lib/ruby/2.4.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
	from /home/prvithani/.rvm/rubies/ruby-2.4.2/lib/ruby/2.4.0/tsort.rb:431:in `each_strongly_connected_component_from'
	from /home/prvithani/.rvm/rubies/ruby-2.4.2/lib/ruby/2.4.0/tsort.rb:349:in `block in each_strongly_connected_component'
	from /home/prvithani/.rvm/rubies/ruby-2.4.2/lib/ruby/2.4.0/tsort.rb:347:in `each'
	from /home/prvithani/.rvm/rubies/ruby-2.4.2/lib/ruby/2.4.0/tsort.rb:347:in `call'
	from /home/prvithani/.rvm/rubies/ruby-2.4.2/lib/ruby/2.4.0/tsort.rb:347:in `each_strongly_connected_component'
	from /home/prvithani/.rvm/rubies/ruby-2.4.2/lib/ruby/2.4.0/tsort.rb:226:in `tsort_each'
	from /home/prvithani/.rvm/rubies/ruby-2.4.2/lib/ruby/2.4.0/tsort.rb:205:in `tsort_each'
	from /home/prvithani/.rvm/gems/ruby-2.4.2/gems/railties-5.1.5/lib/rails/initializable.rb:58:in `run_initializers'
	from /home/prvithani/.rvm/gems/ruby-2.4.2/gems/railties-5.1.5/lib/rails/application.rb:353:in `initialize!'
	from /home/prvithani/.rvm/gems/ruby-2.4.2/gems/railties-5.1.5/lib/rails/railtie.rb:185:in `public_send'
	from /home/prvithani/.rvm/gems/ruby-2.4.2/gems/railties-5.1.5/lib/rails/railtie.rb:185:in `method_missing'
	from /home/prvithani/Workspace/adwyze/config/environment.rb:18:in `<top (required)>'
	from /home/prvithani/.rvm/gems/ruby-2.4.2/gems/activesupport-5.1.5/lib/active_support/dependencies.rb:292:in `require'
	from /home/prvithani/.rvm/gems/ruby-2.4.2/gems/activesupport-5.1.5/lib/active_support/dependencies.rb:292:in `block in require'
	from /home/prvithani/.rvm/gems/ruby-2.4.2/gems/activesupport-5.1.5/lib/active_support/dependencies.rb:258:in `load_dependency'
	from /home/prvithani/.rvm/gems/ruby-2.4.2/gems/activesupport-5.1.5/lib/active_support/dependencies.rb:292:in `require'
	from /home/prvithani/.rvm/gems/ruby-2.4.2/gems/railties-5.1.5/lib/rails/application.rb:329:in `require_environment!'
	from /home/prvithani/.rvm/gems/ruby-2.4.2/gems/railties-5.1.5/lib/rails/command/actions.rb:16:in `require_application_and_environment!'
	from /home/prvithani/.rvm/gems/ruby-2.4.2/gems/railties-5.1.5/lib/rails/commands/generate/generate_command.rb:8:in `help'
	from /home/prvithani/.rvm/gems/ruby-2.4.2/gems/railties-5.1.5/lib/rails/commands/generate/generate_command.rb:17:in `perform'
	from /home/prvithani/.rvm/gems/ruby-2.4.2/gems/thor-0.20.0/lib/thor/command.rb:27:in `run'
	from /home/prvithani/.rvm/gems/ruby-2.4.2/gems/thor-0.20.0/lib/thor/invocation.rb:126:in `invoke_command'
	from /home/prvithani/.rvm/gems/ruby-2.4.2/gems/thor-0.20.0/lib/thor.rb:387:in `dispatch'
	from /home/prvithani/.rvm/gems/ruby-2.4.2/gems/railties-5.1.5/lib/rails/command/base.rb:63:in `perform'
	from /home/prvithani/.rvm/gems/ruby-2.4.2/gems/railties-5.1.5/lib/rails/command.rb:44:in `invoke'
	from /home/prvithani/.rvm/gems/ruby-2.4.2/gems/railties-5.1.5/lib/rails/commands.rb:16:in `<top (required)>'
	from bin/rails:4:in `require'
	from bin/rails:4:in `<main>'

Had the same problem, looks like rails loads up Doorkeeper::ApplicationController which calls Doorkeeper.configuration which in turn will fail with Doorkeeper::MissingConfiguration if the config is not set. In other words, the generator needs the config to exist to generate the config…

I don’t know why this happens to some people, when it seems to work fine for others, but I worked around the problem by manually creating the initializer and copy/paste the template:

# config/initializers/doorkeeper.rb

Doorkeeper.configure do
  # Change the ORM that doorkeeper will use (needs plugins)
  orm :active_record

  # This block will be called to check whether the resource owner is authenticated or not.
  resource_owner_authenticator do
    fail "Please configure doorkeeper resource_owner_authenticator block located in #{__FILE__}"
    # Put your resource owner authentication logic here.
    # Example implementation:
    #   User.find_by_id(session[:user_id]) || redirect_to(new_user_session_url)
  end

  # If you want to restrict access to the web interface for adding oauth authorized applications, you need to declare the block below.
  # admin_authenticator do
  #   # Put your admin authentication logic here.
  #   # Example implementation:
  #   Admin.find_by_id(session[:admin_id]) || redirect_to(new_admin_session_url)
  # end

  # Authorization Code expiration time (default 10 minutes).
  # authorization_code_expires_in 10.minutes

  # Access token expiration time (default 2 hours).
  # If you want to disable expiration, set this to nil.
  # access_token_expires_in 2.hours

  # Assign a custom TTL for implicit grants.
  # custom_access_token_expires_in do |oauth_client|
  #   oauth_client.application.additional_settings.implicit_oauth_expiration
  # end

  # Use a custom class for generating the access token.
  # https://github.com/doorkeeper-gem/doorkeeper#custom-access-token-generator
  # access_token_generator '::Doorkeeper::JWT'

  # The controller Doorkeeper::ApplicationController inherits from.
  # Defaults to ActionController::Base.
  # https://github.com/doorkeeper-gem/doorkeeper#custom-base-controller
  # base_controller 'ApplicationController'

  # Reuse access token for the same resource owner within an application (disabled by default)
  # Rationale: https://github.com/doorkeeper-gem/doorkeeper/issues/383
  # reuse_access_token

  # Issue access tokens with refresh token (disabled by default)
  # use_refresh_token

  # Provide support for an owner to be assigned to each registered application (disabled by default)
  # Optional parameter confirmation: true (default false) if you want to enforce ownership of
  # a registered application
  # Note: you must also run the rails g doorkeeper:application_owner generator to provide the necessary support
  # enable_application_owner confirmation: false

  # Define access token scopes for your provider
  # For more information go to
  # https://github.com/doorkeeper-gem/doorkeeper/wiki/Using-Scopes
  # default_scopes  :public
  # optional_scopes :write, :update

  # Change the way client credentials are retrieved from the request object.
  # By default it retrieves first from the `HTTP_AUTHORIZATION` header, then
  # falls back to the `:client_id` and `:client_secret` params from the `params` object.
  # Check out the wiki for more information on customization
  # client_credentials :from_basic, :from_params

  # Change the way access token is authenticated from the request object.
  # By default it retrieves first from the `HTTP_AUTHORIZATION` header, then
  # falls back to the `:access_token` or `:bearer_token` params from the `params` object.
  # Check out the wiki for more information on customization
  # access_token_methods :from_bearer_authorization, :from_access_token_param, :from_bearer_param

  # Change the native redirect uri for client apps
  # When clients register with the following redirect uri, they won't be redirected to any server and the authorization code will be displayed within the provider
  # The value can be any string. Use nil to disable this feature. When disabled, clients must provide a valid URL
  # (Similar behaviour: https://developers.google.com/accounts/docs/OAuth2InstalledApp#choosingredirecturi)
  #
  # native_redirect_uri 'urn:ietf:wg:oauth:2.0:oob'

  # Forces the usage of the HTTPS protocol in non-native redirect uris (enabled
  # by default in non-development environments). OAuth2 delegates security in
  # communication to the HTTPS protocol so it is wise to keep this enabled.
  #
  # force_ssl_in_redirect_uri !Rails.env.development?

  # Specify what grant flows are enabled in array of Strings. The valid
  # strings and the flows they enable are:
  #
  # "authorization_code" => Authorization Code Grant Flow
  # "implicit"           => Implicit Grant Flow
  # "password"           => Resource Owner Password Credentials Grant Flow
  # "client_credentials" => Client Credentials Grant Flow
  #
  # If not specified, Doorkeeper enables authorization_code and
  # client_credentials.
  #
  # implicit and password grant flows have risks that you should understand
  # before enabling:
  #   http://tools.ietf.org/html/rfc6819#section-4.4.2
  #   http://tools.ietf.org/html/rfc6819#section-4.4.3
  #
  # grant_flows %w(authorization_code client_credentials)

  # Under some circumstances you might want to have applications auto-approved,
  # so that the user skips the authorization step.
  # For example if dealing with a trusted application.
  # skip_authorization do |resource_owner, client|
  #   client.superapp? or resource_owner.admin?
  # end

  # WWW-Authenticate Realm (default "Doorkeeper").
  # realm "Doorkeeper"
end

Under Rails 7, I had to comment the following line of config/environment.rb for the setup to work

Rails.application.initialize!

Worked for me in Rails 6 with the same issue!

Still having this problem on a fresh install of rails 7.0.4

None of the above solutions resolve, even manually adding the initialization file does not fix. Seems like a critical bug…

This just happened to me; and the reason was because I already had the use_doorkeeper statement in the routes.rb.

Deleting that line fixed it 😄

Can’t reproduce the issue, so I’m closing this issue due to lack of activity. If somebody wants to reopen it - please, provide maximum information bout the env, doorkeeper initializer, Gemfile.lock and other useful data