Skip to content

Instantly share code, notes, and snippets.

@frasertweedale
Last active May 10, 2019 04:30
Show Gist options
  • Save frasertweedale/919fe0e2bdc922b3478528882aa20164 to your computer and use it in GitHub Desktop.
Save frasertweedale/919fe0e2bdc922b3478528882aa20164 to your computer and use it in GitHub Desktop.
Example program for HTTP SPNEGO
import base64
import gssapi
import gssapi.raw
import requests
alice = gssapi.Name('[email protected]')
rcreds = gssapi.raw.acquire_cred_with_password(alice, '4me2Test').creds
creds = gssapi.Credentials(rcreds)
svcname = gssapi.Name('[email protected]', gssapi.NameType.hostbased_service)
svcname = gssapi.Name('[email protected]', gssapi.NameType.hostbased_service)
ctx = gssapi.SecurityContext(name=svcname, creds=creds)
authdata = base64.b64encode(ctx.step())
url = 'https://f24-2.ipa.local/ca/rest/account/login?gssapi='
url = 'https://f24-2.ipa.local/ipa'
headers = {}
headers['Authorization'] = 'Negotiate {}'.format(authdata)
resp = requests.get(url, headers=headers)
print resp.status_code
print resp.headers
print resp.text
import base64
import getpass
import gssapi
import gssapi.raw
import requests
me = gssapi.Name('[email protected]')
rcreds = gssapi.raw.acquire_cred_with_password(me, getpass.getpass()).creds
creds = gssapi.Credentials(rcreds)
svcname = gssapi.Name(
'HTTP/[email protected]',
#'HTTP/[email protected]',
gssapi.NameType.kerberos_principal)
ctx = gssapi.SecurityContext(name=svcname, creds=creds)
authdata = base64.b64encode(ctx.step())
url = 'https://errata.devel.redhat.com/errata'
headers = {}
headers['Authorization'] = 'Negotiate {}'.format(authdata)
print 'REQUEST HEADERS:'
print headers
resp = requests.get(url, headers=headers, verify=False)
print 'RESPONSE:'
print resp.status_code
print resp.headers
print resp.text[:68]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment