title: Callback for Omniauth-Trello (RoR) - can't sign in
body: <p>I am using RoR 5.2, devise and omniauth-trello gem.
  I can't sign in with Trello. 
  I need to create ability to sign in without existing user with returned provider and uid: it should create user if it doesn't exist.</p>
  
  <p>I have already added in <strong>config/routes.rb:</strong></p>
  
  <pre><code>devise_for :users, controllers: { omniauth_callbacks: 'omniauth_callbacks' }
  </code></pre>
  
  <p><strong>config/initializers/devise.rb:</strong></p>
  
  <pre><code>config.omniauth :trello, "#{Rails.application.credentials.trello[:key]}", "#{Rails.application.credentials.trello[:secret]}"
  </code></pre>
  
  <p><strong>config/initializers/omniauth.rb</strong></p>
  
  <pre><code>Rails.application.config.middleware.use OmniAuth::Builder do
        provider :trello, Rails.application.credentials.trello[:key], Rails.application.credentials.trello[:secret],
                 app_name: "Trello-Rooney", scope: 'read,write,account', expiration: 'never'
  end
  </code></pre>
  
  <p><strong>app/controllers/omniauth_callbacks_controller.rb</strong></p>
  
  <pre><code>class OmniauthCallbacksController &lt; Devise::OmniauthCallbacksController
  
        def trello
          @user = User.from_omniauth(request.env['omniauth.auth'])
  
          if @user.persisted?
            sign_in_and_redirect @user, event: :authentication
            set_flash_message(:notice, :success, kind: 'Trello') if is_navigational_format?
          end
        end
  
  end
  </code></pre>
  
  <p><strong>app/models/user.rb</strong></p>
  
  <pre><code>class User &lt; ApplicationRecord
    # Include default devise modules. Others available are:
    # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
    devise :database_authenticatable, :registerable,
           :recoverable, :rememberable, :validatable, :omniauthable, omniauth_providers: %i[trello]
  
  
    def self.from_omniauth(auth)
      user = User.where(provider: auth.provider, uid: auth.uid.to_s).first
      return user if user
  
      email = auth.info[:email]
  
      while email.nil?
        generated_email = "#{SecureRandom.base58(10)}@roonyx.trello"
        if User.where(email: generated_email).blank?
          email = generated_email
        end
      end
  
      user = User.where(email: email).first
  
      if user
        user.update(provider: auth.provider, uid: auth.uid)
      else
        password = Devise.friendly_token[0, 12]
        user = User.create!(email: email, password: password, password_confirmation: password, provider: auth.provider, uid: auth.uid)
      end
      user
    end
  
  
  end
  </code></pre>
  
  <p>But when I am trying to sign in with Trello, I see this in console. Looks like it doesn't cause my callback. Can anyone help? Thank you in advance.</p>
  
  <pre><code>E, [2019-05-13T14:10:29.647241 #19958] ERROR -- omniauth: (trello) Authentication failure! service_unavailable: Net::HTTPFatalError, 500 "Internal Server Error"
  [2019-05-13 14:10:29] (pida=19958)   INFO -- : Processing by OmniauthCallbacksController#failure as HTML
  [2019-05-13 14:10:29] (pida=19958)   INFO -- :   Parameters: {"oauth_token"=&gt;"47215df2b25b4fc089953da32acf0730", "oauth_verifier"=&gt;"8a0b310f2afe98d0aebbd2073efc5b54"}
  [2019-05-13 14:10:29] (pida=19958)   INFO -- : Redirected to http://localhost:3000/users/sign_in
  [2019-05-13 14:10:29] (pida=19958)   INFO -- : Completed 302 Found in 1ms (ActiveRecord: 0.0ms)
  </code></pre>