OmniAuth Invalid Response Error

时光总嘲笑我的痴心妄想 提交于 2019-12-02 00:59:58

I've been running into this error in the same situation. Devise is rescuing an unrelated Exception and handling it as an auth failure. I preempted Devise by handling the exception in the controller:

  # authentications_controller.rb
  def create
    omniauth = request.env["omniauth.auth"]
    # Blah
    # blah
    # Blark!
  rescue Exception => e
    # Just spit out the error message and a backtrace.
    render :text => "<html><body><pre>" + e.to_s + "</pre><hr /><pre>" + e.backtrace.join("\n") + "</pre></body></html>"

For anyone else that finds this via google, heroku_backup_task was the culprit for me. When we add that to our gemfile, OmniAuth decoding fails leading to this error. I assume it's some json conflict.

Not sure why it doesn't happen on 1.9.2, but I can confirm that upgrading to 1.9.2 fixes it, but can cause other issues in your app if all your gems don't play nice, and downgrading heroku appears to be a no-go. I'm going to have to destroy and re-create my app now that I've discovered the issue.

Ok,

I'm not sure why this has worked but it has so I'll post here in the effort to help someone else that ends up with this issue.

I upgraded my app to use ruby 1.9.2 (way of the future!) and bang, it just worked again. No idea why but hey sometimes that's just the way it goes.

Upgrading was really easy though. I was sparked into upgrade action by this dhh tweet & found this and this to be really helpful resources in making sure your 1.8.7 code will work in 1.9.2. Props to heroku as well for making it so easy to upgrade an app.

I have had same problem and, I think I find out the solution. In Tutorial, RailsCast #235 gives authentications_controller.rb

def create
  auth = request.env["rack.auth"]
  current_user.authentications.find_or_create_by_provider_and_uid(auth['provider'],
                                                                  auth['uid'])
  flash[:notice] = "Authentication successful."
  redirect_to authentications_url
end

but,

auth = request.env["rack.auth"]

is no longer exists in omniouth 0.2.3

auth = request.env["omniauth.auth"]

is correct.

OK, so, sorry to post to such an old question, however having followed the Railscasts tutorial for this I was getting the same error. I have come to the conclusion that the error handling of the omniauth-twitter gem is causing the confusion, because it hides the underlying errors. I solved the problem by adding the omniauth-facebook gem to my app and authenticating with this.

This quickly uncovered the root error in my app, which was that I had put the User.create_with_omniauth method into the user controller rather than the model, a newbie error but easy to resolve.

My error was easy, and somewhat irrelevant, by using the facebook gem, the error handling allowed me to understand the problem and resolve quickly. If you are struggling with this problem, try facebook or another provider and see if you can get to the root problem more easily, and certainly avoiding some of the more complex issues such as upgrades to ruby!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!