Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added support basic authorization #25

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion jsonrpclib/jsonrpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,14 @@ class TransportMixIn(object):
_connection = (None, None)
_extra_headers = []

def set_basic_auth(self, user, password):
import base64
self.__auth = 'Basic %s' % (base64.b64encode('%s:%s' % (user, password)))

def send_content(self, connection, request_body):
if self.__auth != None :
connection.putheader("Authorization", self.__auth)

connection.putheader("Content-Type", "application/json-rpc")
connection.putheader("Content-Length", str(len(request_body)))
connection.endheaders()
Expand Down Expand Up @@ -200,7 +207,7 @@ class ServerProxy(XMLServerProxy):
"""

def __init__(self, uri, transport=None, encoding=None,
verbose=0, version=None):
verbose=0, version=None, user=None, password=None):
import urllib
if not version:
version = config.version
Expand All @@ -227,6 +234,8 @@ def __init__(self, uri, transport=None, encoding=None,
transport = SafeTransport()
else:
transport = Transport()
if user != None and password != None:
transport.set_basic_auth(user, password)
self.__transport = transport
self.__encoding = encoding
self.__verbose = verbose
Expand Down