-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhttpie_xsisip.py
32 lines (26 loc) · 988 Bytes
/
httpie_xsisip.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
"""
BROADSOFT XSI-SIP auth plugin for HTTPie.
"""
from httpie.plugins import AuthPlugin
import base64
__version__ = '1.0.0'
__author__ = 'Pietro Bertera'
__licence__ = 'BSD'
class HttpXSISIP:
def __init__(self, xsi_username, sip_username, sip_password):
self.xsi_username = xsi_username
self.sip_username = sip_username
self.sip_password = sip_password
def __call__(self, r):
r.headers['Authorization'] = 'BroadWorksSIP basic="' + \
base64.b64encode('%s:%s' % (self.xsi_username, self.sip_password)) + \
'",sipUser="' + base64.b64encode(self.sip_username) + '"'
return r
class XSISIPAuthPlugin(AuthPlugin):
name = 'Broadsoft XSI-SIP auth'
auth_type = 'xsisip'
description = ''
auth_parse = False #do not parse user:password
def get_auth(self):
(xsi_username, sip_username, sip_password) = self.raw_auth.split(':')
return HttpXSISIP(xsi_username, sip_username, sip_password)