开发者

Why does OmniAuth pass requests onto the next middleware?

OmniAuth works great, but I've noticed when using it in a Rails v2.3.6 app that it passes requests on to the next Rack middleware, even though it ends up handling the request itself, and responding with a Redirect.

Code Excerpt: (from 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

And my app, upon being passed the /auth/provider request, throws an exception and returns a 404. The user doesn't see this, but ExceptionNotifier and the logs do. To deal with this, I've created another middleware that just responds with [200,{},[]] for a开发者_开发知识库ll paths like /auth/provider_name.

Why does OmniAuth pass the request down the middleware stack?


if you don't want OmniAuth to pass the next middleware you just have to change the order of the middlewares. Example

Middleware_1 Middleware_2 ... OmniAuth Your_APP

and it will work :)


In Rails 3.1.1 I got such problem.

When you have a route in your app that respond to auth/:provider_name and not returns 404 error, it will be used instead of following omniauth flow.

To solve you need to remove it or force to return responce with 404 status

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜