requests-gssapi is an HTTP library that extends `python-requests` to provide optional GSSAPI authentication support, including mutual authentication. It acts as a fully backward-compatible shim for the older `requests-kerberos` library, allowing for a seamless transition. The current version is 1.4.0 and requires Python >=3.8. It is actively maintained with releases occurring as needed.
pip install requests-gssapiVerified import paths — ran on the pinned version, not inferred.
Demonstrates a basic GET request using `HTTPSPNEGOAuth` to an GSSAPI-protected endpoint. It's crucial to have a valid Kerberos Ticket-Granting Ticket (TGT) obtained via `kinit` or similar methods before running. Optional parameters like `opportunistic_auth` and `target_name` are available for more advanced scenarios.
Set `mutual_authentication` explicitly to `requests_gssapi.DISABLED` (or `gssapi.C_NO_FLAG`) in `HTTPSPNEGOAuth` if not needed and issues occur: `auth=HTTPSPNEGOAuth(mutual_authentication=requests_gssapi.DISABLED)`.
Instantiate a new `HTTPSPNEGOAuth` object for each thread or request, or ensure `HTTPSPNEGOAuth` instances are not shared concurrently across requests to the same target hostname.
Be aware of this limitation for requests with bodies. If possible, design the server to tolerate retransmitted requests or consider alternative authentication flows for such operations if issues persist.
If you intend to use channel bindings, ensure `pip install cryptography` is executed alongside `requests-gssapi`.
Run `kinit` in your shell to obtain a TGT before executing the Python script. Verify with `klist`.
Explicitly specify the SPNEGO mechanism:
```python
import gssapi
from requests_gssapi import HTTPSPNEGOAuth
try:
spnego_mech = gssapi.mechs.Mechanism.from_sasl_name("GS2-SPNEGO")
except AttributeError:
# Fallback for older gssapi versions or specific environments
spnego_mech = gssapi.OID.from_int_seq("1.3.6.1.5.5.2")
auth = HTTPSPNEGOAuth(mech=spnego_mech)
response = requests.get("http://your-spnego-server.com", auth=auth)
```If mutual authentication is not strictly required for your security model, disable it: `auth=HTTPSPNEGOAuth(mutual_authentication=requests_gssapi.DISABLED)`. Ensure your server is correctly configured for GSSAPI/SPNEGO without requiring additional mutual authentication rounds if that's the desired behavior.