1

OmniAuth工作得很好,但我注意到在 Rails v2.3.6 应用程序中使用它时,它会将请求传递到下一个 Rack 中间件,即使它最终自己处理请求并使用重定向响应。

代码摘录:(来自Github

if current_path == request_path && OmniAuth.config.allow....
  status, headers, body = *call_app!
  @response = Rack::Response.new(body, status, headers)
  request_phase
elsif current_path == callback_path
  callback_phase
else
  ...
end

我的应用程序在通过/auth/provider请求后会引发异常并返回 404。用户看不到这一点,但ExceptionNotifier日志会看到。为了解决这个问题,我创建了另一个中间件,它只响应[200,{},[]]所有路径,如/auth/provider_name.

为什么 OmniAuth 将请求向下传递到中间件堆栈?

4

2 回答 2

0

如果您不希望 OmniAuth 传递下一个中间件,您只需更改中间件的顺序。例子

Middleware_1 Middleware_2 ... OmniAuth Your_APP

它会工作:)

于 2011-03-25T15:52:50.720 回答
0

在 Rails 3.1.1 中我遇到了这样的问题。

当您的应用程序中有响应auth/:provider_name但不返回 404 错误的路由时,将使用它而不是遵循omniauth 流。

要解决,您需要将其删除或强制以 404 状态返回响应

于 2011-10-12T13:07:16.187 回答