Skip to main content

WWW-Authenticate Parser (wwwauth)

Copyright 2026 Ian Pilcher <arequipeno@gmail.com>

This a parser for WWW-Authenticate HTTP headers, as defined in RFC 9110.

License

This repository uses multiple licenses.

Installation

The library consists of a single module, wwwauth.py. Simply copy the file to a directory in your Python path.

Usage

The API is extremely simple. A header string is passed to the parse function and a list of Challenge objects is returned. (If the string is not a valid WWW-Authenticate header, a ValueError is raised.

def parse(hdr: str) -> list[Challenge]:
    """Parse a ``WWW-Authenticate`` header.

    Args:
        hdr: The contents of the header (or multiple ``WWW-Authenticate``
            headers separated by commas).

    Returns:
        A list of parsed authentication challenges.

    Raises:
        ValueError: If the header contents are not valid.
    """
    ...

A Challenge object has 1 mandatory and 2 optional (and mutually exclusive) fields.

  • scheme (str) – The authentication scheme of the challenge, normalized to all lowercase (basic, bearer, digest, negotiate, etc.).

  • token (str | None) – Set if the WWW-Authenticate header included token68 data for the challenge. The token data is not decoded or otherwise modified.

  • params (dict[str, str] | None) – Set if the WWW-Authenticate header included parameters for the challenge. Parameter names (but not values) are normalized to all lowercase.

scheme is set in all Challenge objects. One of token or params may be set.

@dataclasses.dataclass
class Challenge:
    """A single parsed ``WWW-Authenticate`` challenge.

    A challenge that carries data sets exactly one of :attr:`token` (a token68
    credential) or :attr:`params` (auth parameters); a bare scheme leaves both
    ``None``.  The :attr:`scheme` and every parameter name are normalized to
    lowercase (both are case-insensitive per RFC 9110); the token68 credential
    and parameter values are left as received, as they are case-sensitive.

    Raises:
        ValueError: If :arg:`token` and :arg:`params` are both specified.
    """

    scheme: str
    """The authentication scheme (normalized to lowercase)."""

    token: str | None = dataclasses.field(default=None, kw_only=True)
    """Authentication scheme ``token68`` data, if any."""

    params: dict[str, str] | None = dataclasses.field(
        default=None, kw_only=True
    )
    """Authentication scheme parameters, if any.

    Parameters names are normalized to lowercase.
    """
    ...

Example

>>> import wwwauth
>>>
>>> challenges = wwwauth.parse(
... 'Bearer token68date===, '
... 'Bearer realm="https://foo.bar",SCOPE="baz", '
... 'BareChallenge,'
... )
>>>
>>> for c in challenges:
...     print(c)
...
Challenge(scheme='bearer', token='token68date===', params=None)
Challenge(scheme='bearer', token=None, params={'realm': 'https://foo.bar', 'scope': 'baz'})
Challenge(scheme='barechallenge', token=None, params=None)

Note that the challenge types and parameter names have all been normalized to all lowercase.

Notes

  • As required by RFC 9110, whitespace and extra commas within the header string are ignored.

  • The parser only parses the structure of theWWW-Authenticate header itself. It does not validate the individual challenges within the header. For example, the Basic authentication scheme does not accept token68 data, but this library will parse and return such an invalid challenge.

    >>> wwwauth.parse('basic kfjdfjkfddkfjdj==')
    [Challenge(scheme='basic', token='kfjdfjkfddkfjdj==', params=None)]
    
  • An incomplete authentication parameter list may be parsed as token68 data.

    >>> wwwauth.parse('basic realm=')
    [Challenge(scheme='basic', token='realm=', params=None)]
    

    Although surprising, this is correct, because realm= is valid token68 data.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wwwauth-0.1.1.tar.gz (40.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

wwwauth-0.1.1-py3-none-any.whl (13.4 kB view details)

Uploaded Python 3

File details

Details for the file wwwauth-0.1.1.tar.gz.

File metadata

  • Download URL: wwwauth-0.1.1.tar.gz
  • Upload date:
  • Size: 40.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for wwwauth-0.1.1.tar.gz
Algorithm Hash digest
SHA256 0babe6c0ef0b9d68c70f602375db348f1799060314e8d2241e40df711d61b6fd
MD5 cfca26b1e59cc404053b5cbb5e6218ac
BLAKE2b-256 de246bc131525df4a2f01e84c8ada9859b3eacbaca98777c36083b7fd4a434b0

See more details on using hashes here.

Provenance

The following attestation bundles were made for wwwauth-0.1.1.tar.gz:

Publisher: python-publish.yml on ipilcher/wwwauth

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file wwwauth-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: wwwauth-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 13.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for wwwauth-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3e767f9b0ce957cb7f7ad95224fd52e28b2edfed4143d2c4907be97c2267ccc6
MD5 1e054b572096947b1d30851864515fbb
BLAKE2b-256 b932ee07104b4e6599757a9e06867c702edf06991428df4e8788e836d08b3594

See more details on using hashes here.

Provenance

The following attestation bundles were made for wwwauth-0.1.1-py3-none-any.whl:

Publisher: python-publish.yml on ipilcher/wwwauth

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page