Class: Rack::OAuth2::Server::Resource

Inherits:
Abstract::Handler show all
Defined in:
lib/rack/oauth2/server/resource.rb,
lib/rack/oauth2/server/resource/error.rb,
lib/rack/oauth2/server/resource/bearer.rb,
lib/rack/oauth2/server/resource/bearer/error.rb

Direct Known Subclasses

Bearer

Defined Under Namespace

Modules: ErrorMethods Classes: BadRequest, Bearer, Forbidden, Request, Unauthorized

Constant Summary collapse

ACCESS_TOKEN =
'rack.oauth2.access_token'
DEFAULT_REALM =
'Protected by OAuth 2.0'

Instance Attribute Summary collapse

Attributes inherited from Abstract::Handler

#authenticator, #response

Instance Method Summary collapse

Methods inherited from Abstract::Handler

#call

Constructor Details

#initialize(app, realm = nil, &authenticator) ⇒ Resource

Returns a new instance of Resource.



9
10
11
12
13
# File 'lib/rack/oauth2/server/resource.rb', line 9

def initialize(app, realm = nil, &authenticator)
  @app = app
  @realm = realm
  super(&authenticator)
end

Instance Attribute Details

#realmObject

Returns the value of attribute realm.



7
8
9
# File 'lib/rack/oauth2/server/resource.rb', line 7

def realm
  @realm
end

#requestObject

Returns the value of attribute request.



7
8
9
# File 'lib/rack/oauth2/server/resource.rb', line 7

def request
  @request
end

Instance Method Details

#_call(env) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/rack/oauth2/server/resource.rb', line 15

def _call(env)
  if request.oauth2?
    access_token = authenticate! request.setup!
    env[ACCESS_TOKEN] = access_token
  end
  @app.call(env)
rescue Rack::OAuth2::Server::Abstract::Error => e
  e.realm ||= realm
  e.finish
end