Class: OAuth2::Provider::Rack::ResourceRequest
- Inherits:
-
Rack::Request
- Object
- Rack::Request
- OAuth2::Provider::Rack::ResourceRequest
show all
- Includes:
- Responses
- Defined in:
- lib/oauth2/provider/rack/resource_request.rb
Instance Method Summary
collapse
Methods included from Responses
#authentication_required!, #insufficient_scope!, #invalid_request!, json_error, only_supported, redirect_with_code, redirect_with_error, unauthorized
Instance Method Details
#authenticate_request!(options, &block) ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/oauth2/provider/rack/resource_request.rb', line 31
def authenticate_request!(options, &block)
if authenticated?
if options[:scope].nil? || has_scope?(options[:scope])
yield
else
insufficient_scope!
end
else
authentication_required!
end
end
|
#authenticated? ⇒ Boolean
48
49
50
|
# File 'lib/oauth2/provider/rack/resource_request.rb', line 48
def authenticated?
authorization.present?
end
|
#authorization ⇒ Object
43
44
45
46
|
# File 'lib/oauth2/provider/rack/resource_request.rb', line 43
def authorization
validate_token!
@authorization
end
|
27
28
29
|
# File 'lib/oauth2/provider/rack/resource_request.rb', line 27
def
@authorization_header ||= Rack::Auth::AbstractRequest.new(env)
end
|
#block_invalid_request ⇒ Object
64
65
66
67
68
|
# File 'lib/oauth2/provider/rack/resource_request.rb', line 64
def block_invalid_request
if token_from_param && && (token_from_param != )
invalid_request! 'both authorization header and oauth_token provided, with conflicting tokens'
end
end
|
#block_invalid_token ⇒ Object
70
71
72
73
74
|
# File 'lib/oauth2/provider/rack/resource_request.rb', line 70
def block_invalid_token
access_token = OAuth2::Provider.access_token_class.find_by_access_token(token)
@authorization = access_token.authorization if access_token
authentication_required! 'invalid_token' if access_token.nil? || access_token.expired?
end
|
#has_token? ⇒ Boolean
13
14
15
|
# File 'lib/oauth2/provider/rack/resource_request.rb', line 13
def has_token?
!token.nil?
end
|
#resource_owner ⇒ Object
52
53
54
|
# File 'lib/oauth2/provider/rack/resource_request.rb', line 52
def resource_owner
authorization && authorization.resource_owner
end
|
#token ⇒ Object
9
10
11
|
# File 'lib/oauth2/provider/rack/resource_request.rb', line 9
def token
token_from_param ||
end
|
21
22
23
24
25
|
# File 'lib/oauth2/provider/rack/resource_request.rb', line 21
def
if .provided?
.params
end
end
|
#token_from_param ⇒ Object
17
18
19
|
# File 'lib/oauth2/provider/rack/resource_request.rb', line 17
def token_from_param
params["oauth_token"]
end
|
#validate_token! ⇒ Object
56
57
58
59
60
61
62
|
# File 'lib/oauth2/provider/rack/resource_request.rb', line 56
def validate_token!
if has_token? && @token_validated.nil?
@token_validated = true
block_invalid_request
block_invalid_token
end
end
|