Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c46a3ca

Browse files
committed
add missing optional properties for the user signup endpoint
1 parent 2f7b429 commit c46a3ca

File tree

2 files changed

+59
-25
lines changed

2 files changed

+59
-25
lines changed

auth0/v3/authentication/database.py

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
from .base import AuthenticationBase
21
import warnings
32

3+
from .base import AuthenticationBase
44

5-
class Database(AuthenticationBase):
65

6+
class Database(AuthenticationBase):
77
"""Database & Active Directory / LDAP Authentication.
88
99
Args:
@@ -35,10 +35,10 @@ def login(self, client_id, username, password, connection, id_token=None,
3535
}
3636
)
3737

38-
def signup(self, client_id, email, password, connection, username=None,
39-
user_metadata=None):
38+
def signup(self, client_id, email, password, connection, username=None, user_metadata=None,
39+
given_name=None, family_name=None, name=None, nickname=None, picture=None):
4040
"""Signup using email and password.
41-
41+
4242
Args:
4343
client_id (str): ID of the application to use.
4444
@@ -53,6 +53,17 @@ def signup(self, client_id, email, password, connection, username=None,
5353
user_metadata (dict, optional): Additional key-value information to store for the user.
5454
Some limitations apply, see: https://auth0.com/docs/metadata#metadata-restrictions
5555
56+
given_name (str, optional): The user's given name(s).
57+
58+
family_name (str, optional): The user's family name(s).
59+
60+
name (str, optional): The user's full name.
61+
62+
nickname (str, optional): The user's nickname.
63+
64+
picture (str, optional): A URI pointing to the user's picture.
65+
66+
5667
See: https://auth0.com/docs/api/authentication#signup
5768
"""
5869
body = {
@@ -64,6 +75,21 @@ def signup(self, client_id, email, password, connection, username=None,
6475
'user_metadata': user_metadata
6576
}
6677

78+
if username:
79+
body.update({'username': username})
80+
if user_metadata:
81+
body.update({'user_metadata': user_metadata})
82+
if given_name:
83+
body.update({'given_name': given_name})
84+
if family_name:
85+
body.update({'family_name': family_name})
86+
if name:
87+
body.update({'name': name})
88+
if nickname:
89+
body.update({'nickname': nickname})
90+
if picture:
91+
body.update({'picture': picture})
92+
6793
return self.post(
6894
'https://{}/dbconnections/signup'.format(self.domain),
6995
data=body

auth0/v3/test/authentication/test_database.py

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import unittest
2+
23
import mock
4+
35
from ...authentication.database import Database
46

57

68
class TestDatabase(unittest.TestCase):
79

810
@mock.patch('auth0.v3.authentication.database.Database.post')
911
def test_login(self, mock_post):
10-
1112
d = Database('my.domain.com')
1213

1314
d.login(client_id='cid',
@@ -35,7 +36,6 @@ def test_login(self, mock_post):
3536

3637
@mock.patch('auth0.v3.authentication.database.Database.post')
3738
def test_signup(self, mock_post):
38-
3939
d = Database('my.domain.com')
4040

4141
# using only email and password
@@ -48,16 +48,15 @@ def test_signup(self, mock_post):
4848

4949
self.assertEqual(args[0], 'https://my.domain.com/dbconnections/signup')
5050
self.assertEqual(kwargs['data'], {
51-
'client_id': 'cid',
52-
'email': '[email protected]',
53-
'password': 'pswd',
54-
'connection': 'conn',
55-
'username': None,
56-
'user_metadata': None
57-
})
58-
51+
'client_id': 'cid',
52+
'email': '[email protected]',
53+
'password': 'pswd',
54+
'connection': 'conn',
55+
'username': None,
56+
'user_metadata': None
57+
})
5958

60-
# Using also username and metadata
59+
# Using also optional properties
6160
sample_meta = {
6261
'hobby': 'surfing',
6362
'preference': {
@@ -69,23 +68,32 @@ def test_signup(self, mock_post):
6968
password='pswd',
7069
connection='conn',
7170
username='usr',
72-
user_metadata=sample_meta)
71+
user_metadata=sample_meta,
72+
given_name='john',
73+
family_name='doe',
74+
name='john doe',
75+
nickname='johnny',
76+
picture='avatars.com/john-doe')
7377

7478
args, kwargs = mock_post.call_args
7579

7680
self.assertEqual(args[0], 'https://my.domain.com/dbconnections/signup')
7781
self.assertEqual(kwargs['data'], {
78-
'client_id': 'cid',
79-
'email': '[email protected]',
80-
'password': 'pswd',
81-
'connection': 'conn',
82-
'username': 'usr',
83-
'user_metadata': sample_meta
84-
})
82+
'client_id': 'cid',
83+
'email': '[email protected]',
84+
'password': 'pswd',
85+
'connection': 'conn',
86+
'username': 'usr',
87+
'user_metadata': sample_meta,
88+
'given_name': 'john',
89+
'family_name': 'doe',
90+
'name': 'john doe',
91+
'nickname': 'johnny',
92+
'picture': 'avatars.com/john-doe',
93+
})
8594

8695
@mock.patch('auth0.v3.authentication.database.Database.post')
8796
def test_change_password(self, mock_post):
88-
8997
d = Database('my.domain.com')
9098

9199
d.change_password(client_id='cid',

0 commit comments

Comments
 (0)