WWW-Authenticate Header Parser

0.9.2 · abandoned · verified Sun Apr 12

This is a tiny Python library designed specifically for parsing complex `WWW-Authenticate` HTTP headers. It simplifies the extraction of authentication scheme names and their parameters, returning them in a `collections.OrderedDict`. The library's last release was in August 2015, indicating it is no longer actively developed or maintained.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to parse a `WWW-Authenticate` header string using the `www_authenticate.parse` function. It simulates a typical header containing multiple authentication challenges (Basic and Digest) and then prints the extracted schemes and their associated parameters.

import www_authenticate

# Simulate a WWW-Authenticate header from a server response
www_authenticate_header = 'Basic realm="Restricted Area", charset="UTF-8", Digest realm="api", nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093", opaque="5ccc069c403ebaf9f0171e9517f40e41"'

parsed_challenges = www_authenticate.parse(www_authenticate_header)

print("Parsed WWW-Authenticate Challenges:")
for scheme, params in parsed_challenges.items():
    print(f"  Scheme: {scheme}")
    print(f"    Parameters: {params}")

# Accessing specific parameters
if 'Basic' in parsed_challenges:
    basic_params = parsed_challenges['Basic']
    print(f"\nBasic Realm: {basic_params.get('realm')}")

if 'Digest' in parsed_challenges:
    digest_params = parsed_challenges['Digest']
    print(f"Digest Nonce: {digest_params.get('nonce')}")

view raw JSON →