Class: Resourceful::BasicAuthenticator
- Inherits:
-
Object
- Object
- Resourceful::BasicAuthenticator
show all
- Defined in:
- lib/resourceful/authentication_manager.rb
Instance Method Summary
collapse
Constructor Details
#initialize(realm, username, password) ⇒ BasicAuthenticator
Returns a new instance of BasicAuthenticator.
32
33
34
35
|
# File 'lib/resourceful/authentication_manager.rb', line 32
def initialize(realm, username, password)
@realm, @username, @password = realm, username, password
@domain = nil
end
|
Instance Method Details
#add_credentials_to(request) ⇒ Object
53
54
55
|
# File 'lib/resourceful/authentication_manager.rb', line 53
def add_credentials_to(request)
request.['Authorization'] = credentials
end
|
#can_handle?(request) ⇒ Boolean
49
50
51
|
# File 'lib/resourceful/authentication_manager.rb', line 49
def can_handle?(request)
Addressable::URI.parse(request.uri).host == @domain
end
|
#credentials ⇒ Object
57
58
59
|
# File 'lib/resourceful/authentication_manager.rb', line 57
def credentials
HTTPAuth::Basic.pack_authorization(@username, @password)
end
|
#update_credentials(challenge) ⇒ Object
45
46
47
|
# File 'lib/resourceful/authentication_manager.rb', line 45
def update_credentials(challenge)
@domain = Addressable::URI.parse(challenge.uri).host
end
|
#valid_for?(challenge_response) ⇒ Boolean
37
38
39
40
41
42
43
|
# File 'lib/resourceful/authentication_manager.rb', line 37
def valid_for?(challenge_response)
return false unless challenge_response.['WWW-Authenticate']
!challenge_response.['WWW-Authenticate'].grep(/^\s*basic/i).find do |a_challenge|
@realm.downcase == /realm="([^"]+)"/i.match(a_challenge)[1].downcase
end.nil?
end
|