heartcombo/devise · error · Devise::OmniAuth::StrategyNotFound

#{name}

Error message

#{name}

What it means

When you configure an OmniAuth provider (config.omniauth :facebook, ...) or declare omniauth_providers on a model, Devise::OmniAuth::Config#strategy_class resolves the provider name to a strategy class: first by scanning OmniAuth.strategies for a registered match, then by trying to autoload OmniAuth::Strategies::<CamelizedProvider>. If neither finds a class, autoload_strategy raises StrategyNotFound (subclass of NameError) with the camelized provider name. The usual root cause is that the omniauth-<provider> gem is not in the bundle or not loaded.

Source

Thrown at lib/devise/omniauth/config.rb:42

      end

      def strategy_class
        @strategy_class ||= find_strategy || autoload_strategy
      end

      def find_strategy
        ::OmniAuth.strategies.find do |strategy_class|
          strategy_class.to_s =~ /#{::OmniAuth::Utils.camelize(strategy_name)}$/ ||
            strategy_class.default_options[:name] == strategy_name
        end
      end

      def autoload_strategy
        name = ::OmniAuth::Utils.camelize(provider.to_s)
        if ::OmniAuth::Strategies.const_defined?(name)
          ::OmniAuth::Strategies.const_get(name)
        else
          raise StrategyNotFound, name
        end
      end
    end
  end
end

View on GitHub (pinned to 372b295fe6)

Solutions

  1. Add the matching provider gem to the Gemfile and bundle install: gem "omniauth-facebook" for :facebook, gem "omniauth-google-oauth2" for :google_oauth2, then restart the server.
  2. Fix the provider symbol spelling so Devise::OmniAuth::Utils.camelize(name) matches the gem's strategy class (e.g. :google_oauth2 -> OmniAuth::Strategies::GoogleOauth2).
  3. For custom/in-house strategies, pass the class explicitly: config.omniauth :sso, "id", "secret", strategy_class: MySsoStrategy.
  4. If the gem is present but the error persists, ensure it is required before Devise's initializer (Bundler.require order / require it at the top of the initializer) and stop stale processes: bin/spring stop.

Example fix

# before (Gemfile — no provider gem)
gem "devise"

# config/initializers/devise.rb
Devise.setup do |config|
  config.omniauth :facebook, ENV["FB_ID"], ENV["FB_SECRET"]
end
# -> boot fails: StrategyNotFound "Facebook"

# after (Gemfile)
gem "omniauth-facebook", "~> 8.0"
gem "omniauth-rails_csrf_protection"

# config/initializers/devise.rb (unchanged, now resolves OmniAuth::Strategies::Facebook)
Devise.setup do |config|
  config.omniauth :facebook, ENV["FB_ID"], ENV["FB_SECRET"]
end
Defensive patterns

Strategy: validation

Validate before calling

# Before boot depends on a provider, assert its strategy resolves:
def omniauth_strategy_available?(provider)
  name = ::OmniAuth::Utils.camelize(provider.to_s)
  ::OmniAuth.strategies.any? { |s| s.to_s =~ /#{name}$/ } ||
    ::OmniAuth::Strategies.const_defined?(name)
end

# config/initializers/devise.rb
Rails.application.config.after_initialize do
  Devise.omniauth_configs.each_key do |provider|
    unless omniauth_strategy_available?(provider)
      raise "Add the omniauth-#{provider} gem or pass strategy_class for #{provider}"
    end
  end
end

Type guard

def omniauth_provider_configured?(provider)
  Devise.omniauth_configs.key?(provider) &&
    omniauth_strategy_available?(provider)
end

Try / catch

# Give a clearer boot failure naming the missing gem:
begin
  Devise.setup do |config|
    config.omniauth :facebook, ENV.fetch("FB_ID"), ENV.fetch("FB_SECRET")
  end
rescue Devise::OmniAuth::StrategyNotFound => e
  raise "#{e.message} Add gem 'omniauth-facebook' to the Gemfile and bundle install."
end

Prevention

When it happens

Trigger: config.omniauth :facebook, "APP_ID", "SECRET" in config/initializers/devise.rb without gem "omniauth-facebook" in the Gemfile; a typo in the provider symbol (config.omniauth :gihub ...); model declares devise :omniauthable, omniauth_providers: [:google_oauth2] but omniauth-google-oauth2 is missing; OmniAuth 2.x setup where a legacy gem version no longer registers its strategy; an in-house strategy that was never registered and no :strategy_class option was given.

Common situations: Enabling OAuth login incrementally (routes/model configured, gem forgotten); upgrading from OmniAuth 1.x to 2.x, which requires newer provider gems; typo'd provider names; using custom strategies without passing strategy_class: MyStrategy in the config.omniauth options hash; gem present but not required before the Devise initializer runs.

Related errors


AI-assisted analysis of heartcombo/devise@372b295fe6 (2026-08-21). Data as JSON: /api/errors/9c7dc7acffad1880. Report an issue: GitHub.