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..aa2b806 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