简体   繁体   中英

Rails: twitter omniauth redirect to localhost in production

I have a rails app where my users can login through twitter. Everything was working well until now. When users already have an account they can login correctly. The problem is with new users. When they try to sign up with twitter they are redirected to a wrong url.

The problem might come from the Omniauth Callbacks, But I can't find it ...

Here is my config:

app/controllers/omniauth_callbacks_controller.rb

class OmniauthCallbacksController < Devise::OmniauthCallbacksController
  def all
    user = User.from_omniauth(request.env["omniauth.auth"])

    if user.persisted?
      flash.notice = "Signed in!"
      sign_in_and_redirect user

    else
      session["devise.user_attributes"] = user.attributes
      redirect_to new_user_registration_url
    end

  end
  alias_method :twitter, :all
end

app/models/user.rb

  def self.from_omniauth(auth)
    user = find_or_initialize_by(provider: auth.provider, uid: auth.uid)
    user.name  = auth.info.nickname
    user.image = auth["info"]["image"].sub("_normal", "")

    user.save
    user
  end

  def self.new_with_session(params, session)
    if session["devise.user_attributes"]
      new(session["devise.user_attributes"]) do |user|
        user.attributes = params
        user.valid?
      end
    else
      super
    end
  end

All right, So as I said, in development it's working well, When i try to sign up with a twitter account, the user is well redirected to: http://localhost:3000/users/sign_up but in production if a user sign up he is redirect to http://localhost/users/sign_up wich obviously is a problem;

Any ideas? I can't find what's wrong, everything seems ok in my call back controller.

Most likely you are either sending the callback param to the server wrong, or you have locked the the URL.

Check https://apps.twitter.com/ and see the value of "Callback URL" and "Callback URL Locked" under Application Settings

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM