mirror of
https://github.com/discourse/discourse.git
synced 2024-11-27 11:20:57 -06:00
4e010382cc
Also added some helpful functionality for plugin developers: - Raises RuntimeException if the auth provider has been registered too late - Logs use of deprecated parameters
31 lines
892 B
Ruby
31 lines
892 B
Ruby
# frozen_string_literal: true
|
|
|
|
# omniauth loves spending lots cycles in its magic middleware stack
|
|
# this middleware bypasses omniauth middleware and only hits it when needed
|
|
class Middleware::OmniauthBypassMiddleware
|
|
|
|
def initialize(app, options = {})
|
|
@app = app
|
|
|
|
Discourse.plugins.each(&:notify_before_auth)
|
|
|
|
# if you need to test this and are having ssl issues see:
|
|
# http://stackoverflow.com/questions/6756460/openssl-error-using-omniauth-specified-ssl-path-but-didnt-work
|
|
# OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE if Rails.env.development?
|
|
@omniauth = OmniAuth::Builder.new(app) do
|
|
Discourse.authenticators.each do |authenticator|
|
|
authenticator.register_middleware(self)
|
|
end
|
|
end
|
|
end
|
|
|
|
def call(env)
|
|
if env["PATH_INFO"].start_with?("/auth")
|
|
@omniauth.call(env)
|
|
else
|
|
@app.call(env)
|
|
end
|
|
end
|
|
|
|
end
|