requests-credssp

2.0.0 · active · verified Thu Apr 16

requests-credssp is a Python library that enables HTTPS CredSSP authentication for the popular `requests` library. CredSSP is a Microsoft authentication protocol allowing credentials to be delegated to a server for double-hop authentication. It supports CredSSP protocol versions 2 to 6, initial authentication with NTLM or Kerberos, and message encryption. The library is actively maintained, with the latest major release (v2.0.0) in February 2022.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `requests-credssp` to perform an HTTP GET request with CredSSP authentication. It initializes `HttpCredSSPAuth` with a username and password (preferably from environment variables for security) and then uses it with a standard `requests.get()` call. The `minimum_version` parameter can be used to specify the required CredSSP protocol version for the server.

import requests
import os
from requests_credssp import HttpCredSSPAuth

# It's recommended to retrieve credentials from environment variables or a secure store
username = os.environ.get('CREDSSP_USERNAME', 'DOMAIN\\user')
password = os.environ.get('CREDSSP_PASSWORD', 'password')

# Initialize the CredSSP authentication handler
# minimum_version can be set (e.g., 5) to enforce higher CredSSP protocol versions
credssp_auth = HttpCredSSPAuth(username, password, minimum_version=5)

# Make a request using the CredSSP authentication
try:
    # Replace with your actual CredSSP-enabled endpoint
    response = requests.get("https://server:5986/wsman", auth=credssp_auth, verify=False) 
    response.raise_for_status()
    print(f"Request successful: {response.status_code}")
    print(response.text)
except requests.exceptions.RequestException as e:
    print(f"Request failed: {e}")
    if e.response is not None:
        print(f"Response content: {e.response.text}")

view raw JSON →