http_authenticate
This library provides HTTP Basic authentication helpers on top of the normalized HTTP stack.
The library currently provides these public entities:
http_authenticate_verifier_protocolserver-side verifier protocol for checking plaintext credentialshttp_authenticatecore Basic parsing, generation, request protection, and challenge helpershttp_htpasswd_verifier(_)portable Apache.htpasswdsubset verifier supporting{SHA}entrieshttp_server_basic_handler(_, _, _)portable handler wrapper that applies Basic protection around another object implementinghttp_handler_protocolhttp_router_basic_auth(_, _)router companion category that protects routes declaringbasic_auth/1metadata
API documentation
Open the ../../apis/library_index.html#http_authenticate link in a web browser.
Loading
To load the library, load the loader.lgt file:
| ?- logtalk_load(http_authenticate(loader)).
Testing
To test this library, load the tester.lgt file:
| ?- logtalk_load(http_authenticate(tester)).
Usage overview
Use http_authenticate directly when you need explicit control over
Basic challenge parsing and request verification:
| ?- http_authenticate::protect_request(Request, verifier, Action, [realm('private')]).
Wrap a normal handler with http_server_basic_handler(_, _, _) when
you want a portable middleware-style integration point for Basic
verification:
| ?- Handler = http_server_basic_handler(verifier, app_handler, [realm('private')]).
Use http_router_basic_auth(_, _) in router objects importing
http_router when you want per-route protection driven by normal
route metadata:
authorize_routed_request(Request, Action) :-
^^authorize_basic_auth_request(Request, Action).
route_metadata(show_secret, [basic_auth([])]).
Current scope
deterministic Basic header parsing and generation for
AuthorizationandWWW-Authenticateserver-side request protection through explicit verifier objects with malformed or missing client credentials mapped to
401 Unauthorizedresponses while verifier and configuration errors are rethrownmiddleware-style handler wrapping for generic
http_handler_protocolobjectsroute-level protection through
http_router_basic_auth(_, _)and theauthorize_routed_request/2router hookportable Apache
.htpasswdsubset verification for{SHA}entries using expanded file paths and rejecting malformed decoded SHA-1 digests
Option validation
protect_request/4andunauthorized_response/3-4validate option values at the call boundary using the sharedoptionscategory supportunauthorized_response/4only accepts overlay options forstatus/1,headers/1,body/1, andproperties/1unauthorized-response
status/1values remain limited to401, but the reason phrase follows the shared HTTPtextrules instead of requiring an atom representationinvalid response customization
headers/1andbody/1values are rejected before any normalized HTTP response term is constructed
Non-implemented features
client-side session helpers
automatic role or scope authorization metadata
portable verification of
$apr1$, bcrypt ($2a$,$2b$,$2y$), or traditionalcrypt().htpasswdentries