GSSAPI Authentication Handler for Requests

1.4.0 · active · verified Thu Apr 16

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.

Common errors

Warnings

Install

Imports

Quickstart

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.

import requests
from requests_gssapi import HTTPSPNEGOAuth

# Ensure a Kerberos TGT is available (e.g., by running 'kinit' in your shell)
# For example purposes, hitting a generic domain, replace with your GSSAPI-enabled service

try:
    response = requests.get("http://example.org/protected", auth=HTTPSPNEGOAuth())
    response.raise_for_status()
    print(f"Success: {response.status_code}")
    print(response.text)
except requests.exceptions.RequestException as e:
    print(f"An error occurred: {e}")

# Example with opportunistic authentication and target name override
# response_opportunistic = requests.get(
#     "https://your-service.example.com/api", 
#     auth=HTTPSPNEGOAuth(opportunistic_auth=True, target_name="service-principal@REALM")
# )
# print(response_opportunistic.status_code)

view raw JSON →