Skip to content

Instantly share code, notes, and snippets.

@meetme2meat
Created March 2, 2015 06:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save meetme2meat/079325ce46e95e26acde to your computer and use it in GitHub Desktop.
Save meetme2meat/079325ce46e95e26acde to your computer and use it in GitHub Desktop.
class OmniAuthMiddleware
def initialize(app)
@app = app
end
def call(env)
status, headers, body = @app.call(env)
request = Rack::Request.new(env)
## Match the request is of type omniauth
if request.xhr? and status == 302 and request.path_info =~ /\/auth\/\w+\z/ and body.class == Rack::BodyProxy
location = headers["Location"]
body = ActionDispatch::Response.new
headers = {'Content-Type'=>'text/javascript; charset=utf-8'}
body.body = ["window.location.href='#{location}'"]
body.headers = headers
status = 200
end
[status,headers,body]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment