Class HTTPAuth::Digest::Challenge
In: lib/httpauth/digest.rb
Parent: AbstractHeader

The Challenge class handlers the WWW-Authenticate header. The WWW-Authenticate header is sent by a server when accessing a resource without credentials is prohibided. The header should always be sent together with a 401 status.

See the Digest module for examples

Methods

from_header   new   to_header  

Public Class methods

Parses the information from a WWW-Authenticate header and creates a new WWW-Authenticate instance with this data.

  • challenge: The contents of a WWW-Authenticate header

See initialize for valid options.

[Source]

     # File lib/httpauth/digest.rb, line 407
407:       def self.from_header(challenge, options={})
408:         new Utils.decode_directives(challenge, :challenge), options
409:       end

Create a new instance.

  • h: A Hash with directives, normally this is filled with directives coming from a Challenge instance.
  • options: Use to set of override data from the WWW-Authenticate header
    • :realm: The name of the realm the client should authenticate for. The RFC suggests to use a string like ‘admin@yourhost.domain.com’. Be sure to use a reasonably long string to avoid brute force attacks.
    • :qop: A list with supported qop values. For example: [‘auth-int’]. This will default to [‘auth’]. Although this implementation supports both auth and auth-int, most implementations don‘t. Some implementations get confused when they receive anything but ‘auth’. For maximum compatibility you should leave this setting alone.
    • :algorithm: The preferred algorithm for calculating the digest. For example: ‘MD5-sess‘. This will default to ‘MD5‘. For maximum compatibility you should leave this setting alone.

[Source]

     # File lib/httpauth/digest.rb, line 425
425:       def initialize(h, options={})
426:         @h = h
427:         @h.merge! options
428:       end

Public Instance methods

Encodes directives and returns a string that can be used as the WWW-Authenticate header

[Source]

     # File lib/httpauth/digest.rb, line 431
431:       def to_header
432:         @h[:nonce] ||= Utils.create_nonce @h[:salt]
433:         @h[:opaque] ||= Utils.create_opaque
434:         @h[:algorithm] ||= HTTPAuth::PREFERRED_ALGORITHM
435:         @h[:qop] ||= [HTTPAuth::PREFERRED_QOP]
436:         Utils.encode_directives Utils.filter_h_on(@h,
437:           [:realm, :domain, :nonce, :opaque, :stale, :algorithm, :qop]), :challenge
438:       end

[Validate]