title: undefined local variable or method `flash' for #<Devise::OmniauthCallbacksController:0x007fb5d1741e48>
body: <p>I am building a Rails-API using Omniauth-facebook and Devise-token-auth with Angular and ng-token-auth for the frontend.
  However when logging in with facebook I am presented with the error:</p>
  
  <pre><code>undefined local variable or method `flash' for #&lt;Devise::OmniauthCallbacksController:0x007fd027a51e10&gt;
  </code></pre>
  
  <p>It seems omniauth automatically uses flash middleware however the rails-api doesn't include this and I have been unsuccessfully disabling the use of flash with omniauth.
  My configuration is as below:</p>
  
  <p>application.rb: </p>
  
  <pre><code>    require File.expand_path('../boot', __FILE__)
  
  require "rails"
  # Pick the frameworks you want:
  require "active_model/railtie"
  require "active_job/railtie"
  require "active_record/railtie"
  require "action_controller/railtie"
  require "action_mailer/railtie"
  require "action_view/railtie"
  require "sprockets/railtie"
  # require "rails/test_unit/railtie"
  
  # Require the gems listed in Gemfile, including any gems
  # you've limited to :test, :development, or :production.
  Bundler.require(*Rails.groups)
  
  module PathfinderApi
    class Application &lt; Rails::Application
      config.active_record.raise_in_transactional_callbacks = true
  
  
      config.middleware.insert_before 0, "Rack::Cors" do
        allow do
          origins '*'
          resource '*', :headers =&gt; :any, :methods =&gt; [:get, :post, :options]
        end
      end
  
      config.api_only = true
      config.middleware.use ActionDispatch::Flash
      config.middleware.use ActionDispatch::Cookies
      config.middleware.use ActionDispatch::Session::CookieStore
    end
  end
  </code></pre>
  
  <p>devise_token_auth.rb:</p>
  
  <pre><code>DeviseTokenAuth.setup do |config|
    Rails.application.secrets.facebook_app_secret
    config.change_headers_on_each_request = true
  end
  </code></pre>
  
  <p>devise.rb:</p>
  
  <pre><code>Devise.setup do |config|
    config.navigational_formats = [:json]
  end
  </code></pre>
  
  <p>omniauth.rb:</p>
  
  <pre><code>Rails.application.config.middleware.use OmniAuth::Builder do
    provider :facebook,      ENV['APP_KEY'], ENV['APP_SECRET']
  end
  </code></pre>
  
  <p>I have not managed to disable the flash error with:</p>
  
  <pre><code>config.navigational_formats = [:json]
  </code></pre>
  
  <p>and devise/omniauth is still using flash middleware and throws the error, any help appreciated!</p>