Skip to content

Commit 578e3a3

Browse files
authored
Add /dbconnections/signup with username and metadata (#169)
* add dbconnections/signup with username and metadata * chore comments
1 parent dc43a2b commit 578e3a3

2 files changed

Lines changed: 62 additions & 9 deletions

File tree

auth0/v3/authentication/database.py

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,38 @@ def login(self, client_id, username, password, connection, id_token=None,
3636
headers={'Content-Type': 'application/json'}
3737
)
3838

39-
def signup(self, client_id, email, password, connection):
40-
"""Signup using username and password.
39+
def signup(self, client_id, email, password, connection, username=None,
40+
user_metadata=None):
41+
"""Signup using email and password.
42+
43+
Args:
44+
client_id (str): ID of the application to use.
45+
46+
email (str): The user's email address.
47+
48+
password (str): The user's desired password.
49+
50+
connection (str): The name of the database connection where this user should be created.
51+
52+
username (str, optional): The user's username, if required by the database connection.
53+
54+
user_metadata (dict, optional): Additional key-value information to store for the user.
55+
Some limitations apply, see: https://auth0.com/docs/metadata#metadata-restrictions
56+
57+
See: https://auth0.com/docs/api/authentication#signup
4158
"""
59+
body = {
60+
'client_id': client_id,
61+
'email': email,
62+
'password': password,
63+
'connection': connection,
64+
'username': username,
65+
'user_metadata': user_metadata
66+
}
4267

4368
return self.post(
4469
'https://{}/dbconnections/signup'.format(self.domain),
45-
data={
46-
'client_id': client_id,
47-
'email': email,
48-
'password': password,
49-
'connection': connection,
50-
},
70+
data=body,
5171
headers={'Content-Type': 'application/json'}
5272
)
5373

auth0/v3/test/authentication/test_database.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ def test_signup(self, mock_post):
4141

4242
d = Database('my.domain.com')
4343

44+
# using only email and password
4445
d.signup(client_id='cid',
4546
email='a@b.com',
4647
password='pswd',
@@ -54,7 +55,39 @@ def test_signup(self, mock_post):
5455
'email': 'a@b.com',
5556
'password': 'pswd',
5657
'connection': 'conn',
57-
})
58+
'username': None,
59+
'user_metadata': None
60+
})
61+
self.assertEqual(kwargs['headers'], {
62+
'Content-Type': 'application/json'
63+
})
64+
65+
66+
# Using also username and metadata
67+
sample_meta = {
68+
'hobby': 'surfing',
69+
'preference': {
70+
'color': 'pink'
71+
}
72+
}
73+
d.signup(client_id='cid',
74+
email='a@b.com',
75+
password='pswd',
76+
connection='conn',
77+
username='usr',
78+
user_metadata=sample_meta)
79+
80+
args, kwargs = mock_post.call_args
81+
82+
self.assertEqual(args[0], 'https://my.domain.com/dbconnections/signup')
83+
self.assertEqual(kwargs['data'], {
84+
'client_id': 'cid',
85+
'email': 'a@b.com',
86+
'password': 'pswd',
87+
'connection': 'conn',
88+
'username': 'usr',
89+
'user_metadata': sample_meta
90+
})
5891
self.assertEqual(kwargs['headers'], {
5992
'Content-Type': 'application/json'
6093
})

0 commit comments

Comments
 (0)