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

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

Direct Known Subclasses

Bearer, MAC

Defined Under Namespace

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

Constant Summary

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)

Constructor Details

- (Resource) initialize(app, realm = nil, &authenticator)



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

- (Object) realm

Returns the value of attribute realm



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

def realm
  @realm
end

- (Object) request

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

- (Object) call(env)



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