httpx2-negotiate-sspi
httpx2-negotiate-sspi provides HTTP Negotiate (Kerberos/NTLM) authentication
for httpx2 on Windows, Linux and macOS through the pyspnego library.
The package name mentions sspi for historical reasons; it now uses
pyspnego and works on all major platforms.
It supports:
- Kerberos single sign-on with SSPI (Windows) or the ticket cache (Linux/macOS)
- NTLM with explicit credentials on all platforms
- Extended Protection for Authentication via RFC 5929 TLS channel binding
- Mutual authentication enforcement (CWE-295 mitigation)
Platform support
| Platform | Backend | Requirement |
|---|---|---|
| Windows | SSPI | sspilib (installed automatically) |
| Linux/macOS | GSSAPI | system Kerberos libs (installed automatically) |
Installation
pip install httpx2-negotiate-sspi
On Linux/macOS, system Kerberos libraries must also be present:
# Ubuntu / Debian
sudo apt install libkrb5-dev
# macOS
brew install krb5
Then obtain a ticket before making requests:
kinit user@DOMAIN.COM
Quick start
Default use — single sign-on with the logged-in account:
import httpx2
from httpx2_negotiate_sspi import HttpNegotiateAuth
with httpx2.Client(auth=HttpNegotiateAuth()) as client:
response = client.get("https://iis.contoso.com")
response.raise_for_status()
Async clients use the same auth object (SSPI/GSSAPI calls run in a worker thread so the event loop is not blocked):
import asyncio
import httpx2
from httpx2_negotiate_sspi import HttpNegotiateAuth
async def main() -> None:
async with httpx2.AsyncClient(auth=HttpNegotiateAuth()) as client:
response = await client.get("https://iis.contoso.com")
response.raise_for_status()
asyncio.run(main())
NTLM with explicit credentials — set mutual_authentication=False because
NTLM cannot prove the server's identity:
import httpx2
from httpx2_negotiate_sspi import HttpNegotiateAuth
auth = HttpNegotiateAuth(
username="svc-http-client",
password="hunter2",
domain="CONTOSO",
mutual_authentication=False,
)
with httpx2.Client(auth=auth) as client:
response = client.get("https://intranet.contoso.com")
Explicit SPN host override:
from httpx2_negotiate_sspi import HttpNegotiateAuth
auth = HttpNegotiateAuth(host="adfs.contoso.com")
Enable DNS canonicalization when you need CNAME following:
from httpx2_negotiate_sspi import HttpNegotiateAuth
auth = HttpNegotiateAuth(canonicalize_hostname=True)
Security
Always use HTTPS. HTTP Negotiate authenticates only the initial handshake;
it does not protect the content of subsequent requests or responses. On plain
HTTP there is also no TLS channel binding, which makes relay attacks easier.
The library logs a warning when the request URL scheme is http.
Mutual authentication
By default, mutual_authentication=True. The auth flow raises
MutualAuthenticationError (a subclass of httpx2.HTTPError) when the server
does not send a valid final authentication token.
NTLM cannot prove the server's identity. Set mutual_authentication=False
when you know the endpoint only supports NTLM:
auth = HttpNegotiateAuth(mutual_authentication=False)
SPN and hostname canonicalization
The SPN is constructed as <service>/<host>, e.g. HTTP/server.contoso.com.
- If
host=is provided, it is always used as-is. - If
canonicalize_hostname=False(the default),request.url.hostis used directly. This is safer: DNS canonicalization follows CNAME records, and an attacker who controls DNS can choose the SPN. - If
canonicalize_hostname=True, the host is resolved throughsocket.getaddrinfo(..., AI_CANONNAME). The original host is used as a fallback if DNS fails.
Channel binding
When the httpx2 transport exposes an SSL object, the library automatically
includes a tls-server-end-point channel binding token (RFC 5929). This
prevents authentication relay attacks and is required by servers that enforce
Extended Protection for Authentication.
The hash algorithm follows RFC 5929 §4.1: use the hash of the certificate's signature algorithm, promoting MD5 and SHA-1 to SHA-256.
Limitations
- HTTPS required for content protection. HTTP Negotiate authenticates only the handshake. Content is not protected on plain HTTP, and channel binding is not available.
- NTLM needs the same TCP connection. The NTLM handshake is stateful. If the connection is closed between the first and second request, the authentication will fail.
- No fallback from Negotiate to NTLM. The library tries
Negotiatefirst and thenNTLMif the server advertises both. It does not fall back from Negotiate to NTLM if Negotiate fails to start. - Delegation risk. Only enable
delegate=Truewhen the remote service is trusted to act on the user's behalf (e.g., double-hop scenarios). Delegation allows the server to impersonate the user to other services. - CI tests NTLM and channel binding, not real Kerberos (IIS job). The Windows IIS job on GitHub-hosted runners is not domain-joined, so it tests NTLM. The Linux job runs a real KDC and tests Kerberos.
Configuration reference
| Parameter | Type | Default | Description |
|---|---|---|---|
username |
str | None | Username for explicit credentials |
password |
str | None | Password for explicit credentials |
domain |
str | '.' |
NT domain (. = local account). Prepended to username. |
service |
str | 'HTTP' |
Kerberos service class for the SPN |
host |
str | None | Explicit SPN host override |
delegate |
bool | False | Enable ISC_REQ_DELEGATE / GS2 delegation |
mutual_authentication |
bool | True | Require the server to prove its identity (BREAKING) |
canonicalize_hostname |
bool | False | Follow CNAME records via DNS (BREAKING) |
Troubleshooting
- If you receive
401 Unauthorized, confirm the server advertisesNegotiateorNTLMand the account has permission to access the service. - If
MutualAuthenticationErroris raised with an NTLM server, setmutual_authentication=False. - If Kerberos works only with an explicit
host, verify that the SPN registered in Active Directory matches the host you are connecting to. - On Linux, run
kinit user@REALMand confirmklistshows a valid ticket. - If a service requires Extended Protection, make sure you are using HTTPS and
the transport exposes the peer certificate to
httpx2. - If
canonicalize_hostname=False(the default) causes SPN mismatches, consider settinghost=explicitly or enablingcanonicalize_hostname=True.
Documentation and development
- Documentation: https://achapkowski.github.io/httpx2_negotiate_sspi
- Source: https://github.com/achapkowski/httpx2_negotiate_sspi
- Issues: https://github.com/achapkowski/httpx2_negotiate_sspi/issues
python -m pip install -e .[dev,doc]
python -m coverage run -m unittest discover -s tests
python -m coverage report -m --fail-under=90
python -m sphinx -W -b html docs docs/_build/html
Credits
This package was inspired by
requests-negotiate-sspi.
Metadata
Release files for httpx2-negotiate-sspi 3.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| httpx2_negotiate_sspi-3.0.0.tar.gz | 27.3 kB | With provenance | Details for httpx2_negotiate_sspi-3.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| httpx2_negotiate_sspi-3.0.0-py3-none-any.whl | Python 3 | none | any | Details for httpx2_negotiate_sspi-3.0.0-py3-none-any.whl |
Total release size: 43.5 kB
Release files / httpx2_negotiate_sspi-3.0.0.tar.gz
| Download URL | httpx2_negotiate_sspi-3.0.0.tar.gz |
|---|---|
| Size | 27.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5ae09f413f7b444f36924e42049eccd2fa133b761238ff8ee3a4ee2750356edf
|
|
BLAKE2b-256 checksum How to use checksums |
8d0b777dc59c392c018a2e5bc572ff978351a262ef8d38f82c20a67c9fd28593
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 11, 2026.
Transparency logRelease files / httpx2_negotiate_sspi-3.0.0-py3-none-any.whl
| Download URL | httpx2_negotiate_sspi-3.0.0-py3-none-any.whl |
|---|---|
| Size | 16.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b59c5dbee278353a19bf7bc012e3fcca7d77d3ca239a9627c97b513821f2d5e8
|
|
BLAKE2b-256 checksum How to use checksums |
f04be47297faf40e100498a98f1b4c56bbba43c056a8e1dd3b7741d44d27d101
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 11, 2026.
Transparency logSecurity for httpx2-negotiate-sspi 3.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for httpx2_negotiate_sspi-3.0.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 11, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.