-
-
Save meetme2meat/079325ce46e95e26acde to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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