24
24
instances that are in turn used for managing sessions.
25
25
"""
26
26
27
-
28
27
from __future__ import division
29
28
30
29
from collections import deque
39
38
from .summary import ResultSummary
40
39
from .types import hydrated
41
40
42
-
43
41
DEFAULT_MAX_POOL_SIZE = 50
44
42
45
43
localhost = re .compile (r"^(localhost|127(\.\d+){3})$" , re .IGNORECASE )
@@ -49,10 +47,14 @@ class AuthToken(object):
49
47
""" Container for auth information
50
48
"""
51
49
52
- def __init__ (self , scheme , principal , credentials ):
50
+ def __init__ (self , scheme , principal , credentials , realm = None , parameters = None ):
53
51
self .scheme = scheme
54
52
self .principal = principal
55
53
self .credentials = credentials
54
+ if realm :
55
+ self .realm = realm
56
+ if parameters :
57
+ self .parameters = parameters
56
58
57
59
58
60
class GraphDatabase (object ):
@@ -135,7 +137,7 @@ def __init__(self, address, **config):
135
137
self .encrypted = encrypted
136
138
self .trust = trust = config .get ("trust" , TRUST_DEFAULT )
137
139
if encrypted == ENCRYPTION_ON or \
138
- encrypted == ENCRYPTION_NON_LOCAL and not localhost .match (host ):
140
+ encrypted == ENCRYPTION_NON_LOCAL and not localhost .match (host ):
139
141
if not SSL_AVAILABLE :
140
142
raise RuntimeError ("Bolt over TLS is only available in Python 2.7.9+ and Python 3.3+" )
141
143
ssl_context = SSLContext (PROTOCOL_SSLv23 )
@@ -510,14 +512,28 @@ def __ne__(self, other):
510
512
return not self .__eq__ (other )
511
513
512
514
513
- def basic_auth (user , password ):
515
+ def basic_auth (user , password , realm = None ):
514
516
""" Generate a basic auth token for a given user and password.
515
517
516
518
:param user: user name
517
519
:param password: current password
520
+ :param realm: specifies the authentication provider
521
+ :return: auth token for use with :meth:`GraphDatabase.driver`
522
+ """
523
+ return AuthToken ("basic" , user , password , realm )
524
+
525
+
526
+ def custom_auth (principal , credentials , realm = None , scheme = None , parameters = None ):
527
+ """ Generate a basic auth token for a given user and password.
528
+
529
+ :param principal: specifies who is being authenticated
530
+ :param credentials: authenticates the principal
531
+ :param realm: specifies the authentication provider
532
+ :param scheme: specifies the type of authentication
533
+ :param parameters: parameters passed along to the authenticatin provider
518
534
:return: auth token for use with :meth:`GraphDatabase.driver`
519
535
"""
520
- return AuthToken ("basic" , user , password )
536
+ return AuthToken (scheme , principal , credentials , realm , parameters )
521
537
522
538
523
539
def run (connection , statement , parameters = None ):
0 commit comments