http_digest
This library provides HTTP Digest authentication helpers on top of the normalized HTTP stack.
The library provides these public entities:
http_digest_verifier_protocolserver-side verifier protocol for looking up stored Digest HA1 valueshttp_digestcore Digest parsing, generation, request authorization, request protection, challenge building, andAuthentication-Inforesponse decorationhttp_server_digest_handler(_, _, _, _)portable handler wrapper that applies Digest protection and response decoration around another object implementinghttp_handler_protocolhttp_router_digest_auth(_, _, _)router companion category that protects routes declaringdigest_auth/1metadata and decorates successful protected responses withAuthentication-Infohttp_client_digest_sessionstateful client helper that preserves cookies and retries once when the server replies with a401Digest challenge
The library design keeps the Digest core object stateless and deterministic. State is kept only where it is operationally useful: in verifier objects supplied by applications and in the optional client-side session helper used for cookie storage.
The server-side entities are portable across the backends supported by
the normalized HTTP library. The http_client_digest_session helper
additionally depends on the socket-backed HTTP client stack and is
therefore available on the same backends supported by the
http_client and http_socket libraries.
API documentation
Open the ../../apis/library_index.html#http_digest link in a web browser.
Loading
To load the library, load the loader.lgt file:
| ?- logtalk_load(http_digest(loader)).
Testing
To test this library, load the tester.lgt file:
| ?- logtalk_load(http_digest(tester)).
Usage overview
Use http_digest directly when you need explicit control over Digest
challenge parsing and request verification:
| ?- http_digest::unauthorized_response(Challenge, Response, [realm('private'), nonce_secret('secret')]).
Wrap a normal handler with http_server_digest_handler(_, _, _, _)
when you want a portable middleware-style integration point for Digest
verification:
| ?- Handler = http_server_digest_handler(verifier, app_handler, [realm('private'), nonce_secret('secret')], []).
Use http_router_digest_auth(_, _, _) in router objects importing
http_router when you want per-route protection driven by normal
route metadata:
authorize_routed_request(Request, Action) :-
^^authorize_digest_auth_request(Request, Action).
response_middleware(digest_authentication_info, add_digest_authentication_info).
route_metadata(show_secret, [digest_auth([])]).
Use http_client_digest_session when you need cookie persistence plus
automatic retry after a 401 Digest challenge:
| ?- http_client_digest_session::open(Session, 'Mufasa', 'Circle Of Life'),
http_client_digest_session::get(Session, 'http://127.0.0.1:8080/protected', Response, []),
http_client_digest_session::close(Session).
The current client helper is reactive: it sends the initial request
without an Authorization header and retries automatically only after
receiving a Digest challenge. This keeps the helper small and avoids
maintaining speculative challenge caches inside the client session
state.
For add_authentication_info/4, the nextnonce option accepts
three forms:
nextnonce(false)omits thenextnoncefieldnextnonce(true)generates a fresh nonce usingnonce_secret/1nextnonce(Nonce)emits the explicit nonce atom verbatim
Current scope
deterministic Digest header parsing and generation for challenges, authorizations, and
Authentication-Infoserver-side request protection through explicit verifier objects
middleware-style handler wrapping for server integration
route-level protection and successful-response
Authentication-Infodecoration throughhttp_router_digest_auth(_, _, _)plus theauthorize_routed_request/2andresponse_middleware/2router hooksclient-side Digest retry on top of the existing
http://socket-backed transport and cookie-jar supportMD5, SHA-256, and SHA-512-256 based Digest computations through the
hashesandhmaclibraries; when no algorithm option is provided, the default challenge algorithm remainssha256
Non-implemented features
HTTPS transport support in the client helper
proactive client-side challenge caching across requests
shared or persistent nonce replay stores
auth-intrequest-body hashing support