Module: AuthProxy

Defined in:
lib/auth_proxy.rb,
lib/auth_proxy/errors.rb,
lib/auth_proxy/version.rb

Defined Under Namespace

Classes: App, Config, ProviderValidationError

Constant Summary collapse

VERSION =
"1.0.2"

Class Method Summary collapse

Class Method Details

.appObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/auth_proxy.rb', line 37

def self.app
  Sinatra.new(AuthProxy::App) do
    use Rack::Session::Cookie, key: "auth-proxy.session",
                               domain: "." + AuthProxy.config.cookie_domain,
                               path: "/",
                               expire_after: 2592000,
                               secret: "a-secret"

    set :views, AuthProxy.config.views_path || "#{AuthProxy.root_path}/views"

    if AuthProxy.config.providers.any?
      OmniAuth.config.full_host = AuthProxy.full_url
      OmniAuth.config.failure_raise_out_environments = []
      use OmniAuth::Builder do
        AuthProxy.config.providers.each do |name, p|
          provider p[:provider], p[:app_id], p[:app_secret], p[:options]
        end
      end
    end
  end
end

.configObject



11
12
13
# File 'lib/auth_proxy.rb', line 11

def self.config
  @config
end

.configure {|@config ||= AuthProxy::Config.new| ... } ⇒ Object

Yields:



7
8
9
# File 'lib/auth_proxy.rb', line 7

def self.configure(&block)
  yield @config ||= AuthProxy::Config.new
end

.full_urlObject



25
26
27
28
29
30
# File 'lib/auth_proxy.rb', line 25

def self.full_url
  URI::Generic.build(
    scheme: config.ssl ? "https" : "http",
    host: config.app_domain
  ).to_s
end

.root_pathObject



21
22
23
# File 'lib/auth_proxy.rb', line 21

def self.root_path
  File.expand_path("../../", __FILE__)
end

.validate_auth_request(provider, request) ⇒ Object



32
33
34
35
# File 'lib/auth_proxy.rb', line 32

def self.validate_auth_request(provider, request)
  validator = config.providers[provider.to_s][:validator]
  validator.call(request) unless validator.nil?
end