Class: OAuth2::Provider::Rack::Middleware

Inherits:
Object
  • Object
show all
Defined in:
lib/oauth2/provider/rack/middleware.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Middleware

Returns a new instance of Middleware.



3
4
5
# File 'lib/oauth2/provider/rack/middleware.rb', line 3

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/oauth2/provider/rack/middleware.rb', line 7

def call(env)
  request = env['oauth2'] = ResourceRequest.new(env)

  response = catch :oauth2 do
    if request.path == "/oauth/access_token"
      handle_access_token_request(env)
    else
      @app.call(env)
    end
  end
rescue InvalidRequest => e
  [400, {}, e.message]
end

#handle_access_token_request(env) ⇒ Object



21
22
23
# File 'lib/oauth2/provider/rack/middleware.rb', line 21

def handle_access_token_request(env)
  AccessTokenHandler.new(@app, env).process
end