简体   繁体   English

Rails:Twitter omniauth在生产中重定向到localhost

[英]Rails: twitter omniauth redirect to localhost in production

I have a rails app where my users can login through twitter. 我有一个Rails应用程序,我的用户可以在其中通过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. 当他们尝试使用Twitter进行注册时,会将其重定向到错误的URL。

The problem might come from the Omniauth Callbacks, But I can't find it ... 问题可能来自Omniauth回调,但我找不到...

Here is my config: 这是我的配置:

app/controllers/omniauth_callbacks_controller.rb 应用程序/控制器/ omn​​iauth_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 应用程序/模型/ 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; 好的,正如我说的那样,在开发过程中运行良好,当我尝试使用Twitter帐户进行注册时,用户可以很好地重定向到: http:// localhost:3000 / users / sign_up,但在生产中(如果用户签名)显然,他被重定向到http:// localhost / users / sign_up是个问题;

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. 您很可能是将回调参数错误地发送到服务器,或者您已锁定了URL。

Check https://apps.twitter.com/ and see the value of "Callback URL" and "Callback URL Locked" under Application Settings 检查https://apps.twitter.com/并在“应用程序设置”下查看“回调URL”和“锁定回调URL”的值

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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