Class: HTTPAuth::Digest::AuthenticationInfo
- Inherits:
-
AbstractHeader
- Object
- AbstractHeader
- HTTPAuth::Digest::AuthenticationInfo
- Defined in:
- lib/httpauth/digest.rb
Overview
The AuthenticationInfo class handles the Authentication-Info header. Sending Authentication-Info headers will allow the client to check the integrity of the response, but it isn’t compulsory and will get in the way of pipelined retrieval of resources.
See the Digest module for examples
Instance Attribute Summary
Attributes inherited from AbstractHeader
Class Method Summary collapse
-
.from_credentials(credentials, options = {}) ⇒ Object
Creates a new AuthenticationInfo instance based on the information from Credentials instance.
-
.from_header(auth_info, options = {}) ⇒ Object
Parses the information from a Authentication-Info header and creates a new AuthenticationInfo instance with this data.
Instance Method Summary collapse
-
#initialize(h, options = {}) ⇒ AuthenticationInfo
constructor
Create a new instance.
-
#to_header ⇒ Object
Encodes directives and returns a string that can be used as the AuthorizationInfo header.
-
#update_from_credentials!(options) ⇒ Object
Updates @h from options, generally called after an instance was created with
from_credentials
. -
#validate(options) ⇒ Object
Validates rspauth.
Methods inherited from AbstractHeader
Constructor Details
#initialize(h, options = {}) ⇒ AuthenticationInfo
Create a new instance.
-
h
: A Hash with directives, normally this is filled with the directives coming from a Credentials instance. -
options
: Used to set or override data from the Authentication-Info header-
:digest
: The digest for the specified username and realm. -
:response_body
The body of the response that’s going to be sent to the client. This is a compulsory option if the qop directive is ‘auth-int’.
-
485 486 487 488 |
# File 'lib/httpauth/digest.rb', line 485 def initialize(h, ={}) @h = h @h.merge! end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class HTTPAuth::Digest::AbstractHeader
Class Method Details
.from_credentials(credentials, options = {}) ⇒ Object
Creates a new AuthenticationInfo instance based on the information from Credentials instance.
-
credentials
: A Credentials instance
See initialize
for valid options.
471 472 473 474 475 |
# File 'lib/httpauth/digest.rb', line 471 def self.from_credentials(credentials, ={}) auth_info = new credentials.h auth_info.update_from_credentials! auth_info end |
.from_header(auth_info, options = {}) ⇒ Object
Parses the information from a Authentication-Info header and creates a new AuthenticationInfo instance with this data.
-
auth_info
: The contents of the Authentication-Info header
See initialize
for valid options.
463 464 465 |
# File 'lib/httpauth/digest.rb', line 463 def self.from_header(auth_info, ={}) new Utils.decode_directives(auth_info, :auth), end |
Instance Method Details
#to_header ⇒ Object
Encodes directives and returns a string that can be used as the AuthorizationInfo header
491 492 493 494 |
# File 'lib/httpauth/digest.rb', line 491 def to_header Utils.encode_directives Utils.filter_h_on(@h, [:nextnonce, :qop, :rspauth, :cnonce, :nc]), :auth end |
#update_from_credentials!(options) ⇒ Object
Updates @h from options, generally called after an instance was created with from_credentials
.
497 498 499 500 501 502 503 504 505 |
# File 'lib/httpauth/digest.rb', line 497 def update_from_credentials!() # TODO: update @h after nonce invalidation [:digest, :username, :realm, :password].each do |k| @h[k] = [k] if .include? k end @h[:response_body] = [:response_body] @h[:nextnonce] = Utils.create_nonce @h[:salt] @h[:rspauth] = Utils.calculate_digest(@h, nil, :response) end |
#validate(options) ⇒ Object
Validates rspauth. Returns true
or false
-
options
: The extra options needed to validate rspauth.-
:digest
: The H(a1) digest -
:uri
: request uri -
:nonce
:nonce
-
513 514 515 516 |
# File 'lib/httpauth/digest.rb', line 513 def validate() ho = @h.merge() return @h[:rspauth] == Utils.calculate_digest(ho, @s, :response) end |