From db48126b6a9fb4b2a6b04d21fde443aff967bd3c Mon Sep 17 00:00:00 2001 From: jing Date: Tue, 6 Nov 2018 11:33:25 -0500 Subject: [PATCH 1/3] add auth_token to client --- docs/tutorial/tutorial.rst | 6 +++++- graphspace_python/api/client.py | 16 ++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/docs/tutorial/tutorial.rst b/docs/tutorial/tutorial.rst index 58438fb..5d45f76 100644 --- a/docs/tutorial/tutorial.rst +++ b/docs/tutorial/tutorial.rst @@ -5,11 +5,15 @@ Start here to begin working with `graphspace-python`. Connecting to GraphSpace ------------------------ -You can connect to GraphSpace using your username and password. +You can connect to GraphSpace using your username and password, >>> from graphspace_python.api.client import GraphSpace >>> graphspace = GraphSpace('user1@example.com', 'user1') +or using your username and authentication key. +>>> from graphspace_python.api.client import GraphSpace +>>> graphspace = GraphSpace('user1@example.com', auth_token='Basic dXNlcjFAZXhhbXBsZS5jb206dXNlcjE=') + You can also set the api host using the :meth:`~graphspace_python.api.client.GraphSpace.set_api_host` method if you are using a different server. diff --git a/graphspace_python/api/client.py b/graphspace_python/api/client.py index b56c7ff..6fd5636 100644 --- a/graphspace_python/api/client.py +++ b/graphspace_python/api/client.py @@ -40,14 +40,26 @@ class GraphSpace(object): Groups ] - def __init__(self, username, password): + def __init__(self, username=None, password=None, auth_token=None): """Construct a new 'GraphSpace' client object. Args: username (str): Email of the user. password (str): Password of the user. + auth_token (str): Basic authorization value + + User can connect to GraphSpace using username and password or username and auth_token. + Example: + >>> from graphspace_python.api.client import GraphSpace + >>> graphspace = GraphSpace('user1@example.com', 'user1') + OR + >>> from graphspace_python.api.client import GraphSpace + >>> graphspace = GraphSpace('user1@example.com', auth_token='Basic dXNlcjFAZXhhbXBsZS5jb206dXNlcjE=') """ # self.auth_token = 'Basic %s' % base64.b64encode('{0}:{1}'.format(username, password)) + if auth_token is not None: + userpass = base64.b64decode(auth_token[len('Basic')+1:]) #'username:password' + password = userpass[len(username)+1:] self.auth_token = requests.auth.HTTPBasicAuth(username, password) self.username = username self.api_host = API_HOST @@ -128,7 +140,7 @@ def _make_request(self, method, path, url_params={}, data={}, headers=None): 'Content-Type': 'application/json' } - request_path = 'http://{0}{1}?{2}'.format( + request_path = 'https://{0}{1}?{2}'.format( self.api_host, six.moves.urllib.parse.quote(path.encode('utf-8')), six.moves.urllib.parse.urlencode(url_params, doseq=True) From 0a90113838ee935b35e97ead81e56d25fe1ec9c3 Mon Sep 17 00:00:00 2001 From: JingVT <33851894+JingVT@users.noreply.github.com> Date: Tue, 6 Nov 2018 11:42:29 -0500 Subject: [PATCH 2/3] Update client.py --- graphspace_python/api/client.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/graphspace_python/api/client.py b/graphspace_python/api/client.py index 6fd5636..e2a8ec5 100644 --- a/graphspace_python/api/client.py +++ b/graphspace_python/api/client.py @@ -51,10 +51,10 @@ def __init__(self, username=None, password=None, auth_token=None): User can connect to GraphSpace using username and password or username and auth_token. Example: >>> from graphspace_python.api.client import GraphSpace - >>> graphspace = GraphSpace('user1@example.com', 'user1') - OR - >>> from graphspace_python.api.client import GraphSpace - >>> graphspace = GraphSpace('user1@example.com', auth_token='Basic dXNlcjFAZXhhbXBsZS5jb206dXNlcjE=') + >>> graphspace = GraphSpace('user1@example.com', 'user1') + OR + >>> from graphspace_python.api.client import GraphSpace + >>> graphspace = GraphSpace('user1@example.com', auth_token='Basic dXNlcjFAZXhhbXBsZS5jb206dXNlcjE=') """ # self.auth_token = 'Basic %s' % base64.b64encode('{0}:{1}'.format(username, password)) if auth_token is not None: From a66e1e8638bd3cc6c8725264957b119225564000 Mon Sep 17 00:00:00 2001 From: JingVT <33851894+JingVT@users.noreply.github.com> Date: Tue, 6 Nov 2018 11:44:37 -0500 Subject: [PATCH 3/3] Update client.py --- graphspace_python/api/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/graphspace_python/api/client.py b/graphspace_python/api/client.py index e2a8ec5..aa2b806 100644 --- a/graphspace_python/api/client.py +++ b/graphspace_python/api/client.py @@ -140,7 +140,7 @@ def _make_request(self, method, path, url_params={}, data={}, headers=None): 'Content-Type': 'application/json' } - request_path = 'https://{0}{1}?{2}'.format( + request_path = 'http://{0}{1}?{2}'.format( self.api_host, six.moves.urllib.parse.quote(path.encode('utf-8')), six.moves.urllib.parse.urlencode(url_params, doseq=True)