OmniAuth 无效响应错误

发布于 2024-10-29 19:50:50 字数 655 浏览 2 评论 0原文

我将 OmniAuth 与 Devise 结合使用,允许用户使用 Facebook 登录或使用用户名和密码创建普通帐户。当我最初设置这一切时,我使用了 Railscasts 中的出色指示。两个多月以来,一切都运行良好,但就在前几天,Facebook 登录停止工作。 OmniAuth 将您发送到 facebook 进行身份验证,然后返回: http://localhost:3000/auth/failure?message=invalid_response

Google 对于导致此错误的原因或如何修复它没有任何建议OmniAuth 文档也没有。我也尝试过深入研究他们的代码,但我发现的这个错误的唯一提及是这个,在 /oa-oauth/lib/omniauth/strategies/oauth.rb 中:

rescue ::MultiJson::DecodeError => e
  fail!(:invalid_response, e)
end

有没有人曾经看到这个错误!?知道它是什么或如何修复它吗?这使我无法启动此应用程序,因此我们将非常感谢任何帮助!

谢谢, 杰格

I'm using OmniAuth with Devise to allow users to login with facebook or to create a normal account with a username and password. When I originally set it all up I used the excellent directions from Railscasts. Everything was working very nicely for 2+ months but just the other day the facebook login stopped working. OmniAuth sends you away to the authentication with facebook and then returns with: http://localhost:3000/auth/failure?message=invalid_response

Google has no suggestions on what causes this error or how to fix it and the OmniAuth docs don't either. I've tried digging through their code as well but the only mention of this error I've found is this, in /oa-oauth/lib/omniauth/strategies/oauth.rb:

rescue ::MultiJson::DecodeError => e
  fail!(:invalid_response, e)
end

Has anyone ever seen this error!? Know what it is or how to fix it?! This is keeping me from launching this application so any help would be very very appreciated!

Thanks,
JG

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

故事和酒 2024-11-05 19:50:50

我在同样的情况下遇到了这个错误。 Devise 正在挽救不相关的异常并将其作为身份验证失败处理。我通过处理控制器中的异常来抢占 Devise:

  # 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>"

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>"
不必在意 2024-11-05 19:50:50

对于通过谷歌找到这个的其他人来说,heroku_backup_task 对我来说是罪魁祸首。当我们将其添加到 gemfile 时,OmniAuth 解码失败,导致此错误。我认为这是一些 json 冲突。

不知道为什么它不会在 1.9.2 上发生,但我可以确认升级到 1.9.2 可以修复它,但如果您的所有 gem 都不能很好地发挥作用,则可能会导致您的应用程序出现其他问题,并且降级 heroku 似乎是不行。既然我发现了这个问题,我将不得不销毁并重新创建我的应用程序。

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.

家住魔仙堡 2024-11-05 19:50:50

好吧,

我不确定为什么这会起作用,但它确实有效,所以我会在这里发帖,以努力帮助其他最终遇到此问题的人。

我升级了我的应用程序以使用 ruby​​ 1.9.2(未来的方式!),然后,它又工作了。不知道为什么,但嘿,有时就是这样。

不过升级真的很容易。这条dhh tweet & 激发了我的升级行动发现 这个是非常有用的资源,可确保您的 1.8.7 代码能够在 1.9.2 中运行。也支持 Heroku 使应用程序升级变得如此容易。

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.

假面具 2024-11-05 19:50:50

我遇到了同样的问题,我想我找到了解决方案。
在教程中, RailsCast #235 提供了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

,但是

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

不再存在于omn​​iouth 0.2.3

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

是正确的。

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.

韬韬不绝 2024-11-05 19:50:50

好的,所以,很抱歉发布这样一个老问题,但是在遵循 Railscasts 教程后,我遇到了同样的错误。我得出的结论是,omniauth-twitter gem 的错误处理导致了混乱,因为它隐藏了潜在的错误。我通过将omniauth-facebook gem 添加到我的应用程序并用它进行身份验证解决了这个问题。

这很快就发现了我的应用程序中的根本错误,即我将 User.create_with_omniauth 方法放入用户控制器而不是模型中,这是一个新手错误,但很容易解决。

我的错误很简单,而且有些无关紧要,通过使用 facebook gem,错误处理使我能够理解问题并快速解决。如果您正在努力解决这个问题,请尝试 facebook 或其他提供商,看看您是否可以更轻松地找到根本问题,并且当然可以避免一些更复杂的问题,例如升级到 ruby​​!

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文