title: Omniauth_google_oauth2 Error: redirect_uri_mismatch
body: <p>I am using Devise and Omniauth Google for Login Authentication in my application. Everything works fine, the Google login works fine in my localhost but when I try to test on a VPS, Google throws redirect_uri_mismatch. I couldn't figure out the actual problem. Please help.</p>
  
  <p>My Gemfile</p>
  
  <pre><code>gem 'omniauth'
  gem 'omniauth-oauth2', '~&gt; 1.3.1'
  gem 'omniauth-facebook'
  gem "omniauth-google-oauth2"
  </code></pre>
  
  <p>VPS Configuration</p>
  
  <pre><code>Ruby v - ruby 2.0.0p643 (2015-02-25 revision 49749) [x86_64-linux]
  Rails v - Rails 4.2.5
  </code></pre>
  
  <p>Callback Controller</p>
  
  <pre><code>def google_oauth2
        # You need to implement the method below in your model (e.g. app/models/user.rb)
        @user = User.from_omniauth(request.env["omniauth.auth"])
  
        if @user.persisted?
          flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind =&gt; "Google"
          sign_in_and_redirect @user, :event =&gt; :authentication
        else
          session["devise.google_data"] = request.env["omniauth.auth"].except("extra")
          redirect_to new_user_registration_url
        end
      end
      def failure
          redirect_to root_path
      end
  </code></pre>
  
  <p>Routes</p>
  
  <pre><code>devise_for :users, :path =&gt; "member",:path_names =&gt; {:sign_in =&gt; 'login', :sign_out =&gt; 'logout', :sign_up =&gt; "register"}, :controllers =&gt; { :registrations =&gt; :registrations, :confirmations =&gt; 'confirmations', :omniauth_callbacks =&gt; "callbacks" }
  </code></pre>