-
Notifications
You must be signed in to change notification settings - Fork 1
/
httpie_negotiate.py
32 lines (24 loc) · 954 Bytes
/
httpie_negotiate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
"""
SPNEGO (GSS Negotiate) auth plugin for HTTPie.
"""
import os
from httpie.plugins import AuthPlugin
__version__ = '1.0.1'
__author__ = 'Nan Zou'
__licence__ = 'BSD'
class NegotiateAuthPlugin(AuthPlugin):
name = 'SPNEGO auth'
auth_type = 'negotiate'
description = ''
def get_auth(self, username, password):
from requests_kerberos import HTTPKerberosAuth, OPTIONAL, DISABLED, REQUIRED
pref = os.environ.get("HTTPIE_KERBEROS_MUTUAL")
if pref in ["optional","OPTIONAL"]:
kerberos_auth = HTTPKerberosAuth(mutual_authentication=OPTIONAL)
elif pref in ["disabled","DISABLED"]:
kerberos_auth = HTTPKerberosAuth(mutual_authentication=DISABLED)
elif pref == None or pref in ["required","REQUIRED"]:
kerberos_auth = HTTPKerberosAuth()
else:
raise Exception("Invalid HTTPIE_KEBEROS_MUTUAL value {}".format(pref))
return kerberos_auth