Class: JayDoubleuTee::Authorization

Inherits:
Object
  • Object
show all
Defined in:
lib/jay_doubleu_tee/authorization.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Authorization

Returns a new instance of Authorization.



12
13
14
15
16
# File 'lib/jay_doubleu_tee/authorization.rb', line 12

def initialize(app)
  @app = app
  @decoder = Decoder.new
  @config = JayDoubleuTee.config
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



10
11
12
# File 'lib/jay_doubleu_tee/authorization.rb', line 10

def config
  @config
end

#decoderObject (readonly)

Returns the value of attribute decoder.



10
11
12
# File 'lib/jay_doubleu_tee/authorization.rb', line 10

def decoder
  @decoder
end

Instance Method Details

#call(env) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/jay_doubleu_tee/authorization.rb', line 18

def call(env)
  auth = decoder.call(env["HTTP_AUTHORIZATION"])

  return authorization_error(auth) if unauthorized?(auth)

  with_auth(auth) do
    @app.call(env)
  end
end