Class: OmniAuth::Strategies::Proxy

Inherits:
Object
  • Object
show all
Defined in:
lib/omniauth/strategies/proxy.rb

Constant Summary collapse

PROXY_PATH =
"https://oauth-proxy.fly.dev/proxy"

Instance Method Summary collapse

Constructor Details

#initialize(app, _options = {}) ⇒ Proxy

Returns a new instance of Proxy.



6
7
8
# File 'lib/omniauth/strategies/proxy.rb', line 6

def initialize(app, _options={})
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/omniauth/strategies/proxy.rb', line 10

def call(env)
  status, headers, body = @app.call(env)

  if ENV["OMNIAUTH_PROXY_ENABLED"].present? && status == 302
    location = headers["Location"]

    if is_google?(location) || is_github?(location) || is_auth0?(location) || is_slack?(location)
      headers["Location"] = proxy_uri(location)
    end
  end

  [status, headers, body]
end

#is_auth0?(location) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/omniauth/strategies/proxy.rb', line 32

def is_auth0?(location)
  location.match?("auth0.com/authorize")
end

#is_github?(location) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/omniauth/strategies/proxy.rb', line 28

def is_github?(location)
  location.match?("https://github.com/login/oauth/authorize")
end

#is_google?(location) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/omniauth/strategies/proxy.rb', line 24

def is_google?(location)
  location.match?("https://accounts.google.com/o/oauth2/auth")
end

#is_slack?(location) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/omniauth/strategies/proxy.rb', line 36

def is_slack?(location)
  location.match?("https://slack.com/openid/connect/authorize")
end

#proxy_uri(location) ⇒ Object



40
41
42
43
# File 'lib/omniauth/strategies/proxy.rb', line 40

def proxy_uri(location)
  encoded_uri = Base64.urlsafe_encode64(location)
  PROXY_PATH + "?uri=" + encoded_uri
end