Last active
February 21, 2024 07:45
-
-
Save krzysztofantczak/92094ea4eaf499a948d900c30411fc6f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import requests | |
import pykerberos | |
# Set the path to your custom krb5.conf file | |
custom_krb5_conf_path = '/path/to/your/custom/krb5.conf' | |
# Set the KRB5_CONFIG environment variable to point to your custom krb5.conf file | |
os.environ['KRB5_CONFIG'] = custom_krb5_conf_path | |
# URL of the Kerberos authenticated HTTP server | |
url = 'http://example.com/endpoint' | |
# Specify the username, password, realm, and SPN | |
username = 'your_username' | |
password = 'your_password' | |
realm = 'YOUR.REALM' | |
spn = 'HTTP/server.domain.com@REALM' | |
# Acquire a Kerberos ticket using the provided credentials | |
kerberos_ticket = pykerberos.authGSSClientInit(spn, options="ntlm") | |
kerberos_ticket = pykerberos.authGSSClientStep(kerberos_ticket, '') | |
kerberos_ticket = pykerberos.authGSSClientUnwrap(kerberos_ticket, '') | |
# Add the Kerberos ticket to the headers of the HTTP request | |
headers = {'Authorization': 'Negotiate ' + kerberos_ticket} | |
# Make a GET request (or any other HTTP method as needed) | |
response = requests.get(url, headers=headers) | |
# Check the response | |
if response.status_code == 200: | |
print("Request successful") | |
print("Response body:", response.text) | |
else: | |
print("Request failed with status code:", response.status_code) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment