Class: Resourceful::DigestAuthenticator
- Defined in:
- lib/resourceful/authentication_manager.rb
Instance Attribute Summary collapse
-
#challenge ⇒ Object
readonly
Returns the value of attribute challenge.
-
#domain ⇒ Object
readonly
Returns the value of attribute domain.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#realm ⇒ Object
readonly
Returns the value of attribute realm.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Instance Method Summary collapse
- #add_credentials_to(request) ⇒ Object
- #can_handle?(request) ⇒ Boolean
- #credentials_for(request) ⇒ Object
-
#initialize(realm, username, password) ⇒ DigestAuthenticator
constructor
A new instance of DigestAuthenticator.
- #update_credentials(challenge_response) ⇒ Object
- #valid_for?(challenge_response) ⇒ Boolean
Constructor Details
#initialize(realm, username, password) ⇒ DigestAuthenticator
Returns a new instance of DigestAuthenticator.
67 68 69 70 71 |
# File 'lib/resourceful/authentication_manager.rb', line 67 def initialize(realm, username, password) @realm = realm @username, @password = username, password @domain = nil end |
Instance Attribute Details
#challenge ⇒ Object (readonly)
Returns the value of attribute challenge.
65 66 67 |
# File 'lib/resourceful/authentication_manager.rb', line 65 def challenge @challenge end |
#domain ⇒ Object (readonly)
Returns the value of attribute domain.
65 66 67 |
# File 'lib/resourceful/authentication_manager.rb', line 65 def domain @domain end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
65 66 67 |
# File 'lib/resourceful/authentication_manager.rb', line 65 def password @password end |
#realm ⇒ Object (readonly)
Returns the value of attribute realm.
65 66 67 |
# File 'lib/resourceful/authentication_manager.rb', line 65 def realm @realm end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
65 66 67 |
# File 'lib/resourceful/authentication_manager.rb', line 65 def username @username end |
Instance Method Details
#add_credentials_to(request) ⇒ Object
92 93 94 |
# File 'lib/resourceful/authentication_manager.rb', line 92 def add_credentials_to(request) request.header['Authorization'] = credentials_for(request) end |
#can_handle?(request) ⇒ Boolean
88 89 90 |
# File 'lib/resourceful/authentication_manager.rb', line 88 def can_handle?(request) Addressable::URI.parse(request.uri).host == @domain end |
#credentials_for(request) ⇒ Object
96 97 98 99 100 101 102 |
# File 'lib/resourceful/authentication_manager.rb', line 96 def credentials_for(request) HTTPAuth::Digest::Credentials.from_challenge(@challenge, :username => @username, :password => @password, :method => request.method.to_s.upcase, :uri => Addressable::URI.parse(request.uri).path).to_header end |
#update_credentials(challenge_response) ⇒ Object
73 74 75 76 |
# File 'lib/resourceful/authentication_manager.rb', line 73 def update_credentials(challenge_response) @domain = Addressable::URI.parse(challenge_response.uri).host @challenge = HTTPAuth::Digest::Challenge.from_header(challenge_response.header['WWW-Authenticate'].first) end |
#valid_for?(challenge_response) ⇒ Boolean
78 79 80 81 82 83 84 85 86 |
# File 'lib/resourceful/authentication_manager.rb', line 78 def valid_for?(challenge_response) return false unless challenge_header = challenge_response.header['WWW-Authenticate'] begin challenge = HTTPAuth::Digest::Challenge.from_header(challenge_header.first) rescue HTTPAuth::UnwellformedHeader return false end challenge.realm == @realm end |