Class: Rack::OAuthEcho::Middleware

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/oauth_echo.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Middleware

Returns a new instance of Middleware.



6
7
8
# File 'lib/rack/oauth_echo.rb', line 6

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



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

def call(env)
  if auth_header?(env)
    json_response = auth_request(env)
    if json_response.status == 200
      env['rack-oauth_echo.user_hash'] = auth_request(env).body
      @app.call(env)
    else
      [json_response.status, {}, "Could not authenticate you."]
    end
  else
    @app.call(env)
  end
end