Last active
May 10, 2019 04:30
-
-
Save frasertweedale/919fe0e2bdc922b3478528882aa20164 to your computer and use it in GitHub Desktop.
Example program for HTTP SPNEGO
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 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 |
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 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