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

Skip to content

Commit 0adbf39

Browse files
authored
Merge pull request auth0#96 from saltukalakus/master
Add GET Users-by-email to the Management API
2 parents 0546a9a + 8b205c2 commit 0adbf39

File tree

5 files changed

+89
-4
lines changed

5 files changed

+89
-4
lines changed

README.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,9 @@ Available Management Endpoints
166166
- Stats() ( ``Auth0().stats`` )
167167
- Tenants() ( ``Auth0().tenants`` )
168168
- Tickets() ( ``Auth0().tickets`` )
169-
- Users() ( ``Auth0().users`` )
170169
- UserBlocks() (``Auth0().user_blocks`` )
170+
- Users() ( ``Auth0().users`` )
171+
- UsersByEmail() ( ``Auth0().users_by_email`` )
171172

172173
Available Authentication Endpoints
173174
==================================

auth0/v3/management/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@
1414
from .stats import Stats
1515
from .tenants import Tenants
1616
from .tickets import Tickets
17+
from .user_blocks import UserBlocks
1718
from .users import Users
18-
from .user_blocks import UserBlocks
19+
from .users_by_email import UsersByEmail

auth0/v3/management/auth0.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313
from .stats import Stats
1414
from .tenants import Tenants
1515
from .tickets import Tickets
16-
from .users import Users
1716
from .user_blocks import UserBlocks
17+
from .users import Users
18+
from .users_by_email import UsersByEmail
1819

1920
class Auth0(object):
2021
"""Provides easy access to all endpoint classes
@@ -41,5 +42,6 @@ def __init__(self, domain, token):
4142
self.stats = Stats(domain, token)
4243
self.tenants = Tenants(domain, token)
4344
self.tickets = Tickets(domain, token)
44-
self.users = Users(domain, token)
4545
self.user_blocks = UserBlocks(domain, token)
46+
self.users = Users(domain, token)
47+
self.users_by_email = UsersByEmail(domain, token)

auth0/v3/management/users_by_email.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
from .rest import RestClient
2+
3+
4+
class UsersByEmail(object):
5+
6+
"""Auth0 users by email endpoints
7+
8+
Args:
9+
domain (str): Your Auth0 domain, e.g: 'username.auth0.com'
10+
11+
token (str): Management API v2 Token
12+
13+
telemetry (bool, optional): Enable or disable Telemetry
14+
(defaults to True)
15+
"""
16+
17+
def __init__(self, domain, token, telemetry=True):
18+
self.domain = domain
19+
self.client = RestClient(jwt=token, telemetry=telemetry)
20+
21+
def _url(self):
22+
url = 'https://%s/api/v2/users-by-email' % self.domain
23+
return url
24+
25+
def search_users_by_email(self, email, fields=None, include_fields=True):
26+
"""List or search users.
27+
28+
Args:
29+
30+
email: Email to search
31+
32+
fields (list of str, optional): A list of fields to include or
33+
exclude from the result (depending on include_fields). Empty to
34+
retrieve all fields.
35+
36+
include_fields (bool, optional): True if the fields specified are
37+
to be include in the result, False otherwise.
38+
"""
39+
params = {
40+
'email': email.lower(),
41+
'fields': fields and ','.join(fields) or None,
42+
'include_fields': str(include_fields).lower()
43+
}
44+
return self.client.get(self._url(), params=params)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import unittest
2+
import mock
3+
from ...management.users_by_email import UsersByEmail
4+
5+
6+
class TestUsersByEmail(unittest.TestCase):
7+
8+
@mock.patch('auth0.v3.management.users_by_email.RestClient')
9+
def test_search_users_by_email(self, mock_rc):
10+
mock_instance = mock_rc.return_value
11+
12+
u = UsersByEmail(domain='domain', token='jwttoken')
13+
u.search_users_by_email('[email protected]')
14+
15+
args, kwargs = mock_instance.get.call_args
16+
17+
self.assertEqual('https://domain/api/v2/users-by-email', args[0])
18+
self.assertEqual(kwargs['params'], {
19+
'email': '[email protected]',
20+
'fields': None,
21+
'include_fields': 'true'
22+
})
23+
24+
u.search_users_by_email(email='[email protected]',
25+
fields=['a', 'b'],
26+
include_fields=False)
27+
28+
args, kwargs = mock_instance.get.call_args
29+
30+
self.assertEqual('https://domain/api/v2/users-by-email', args[0])
31+
self.assertEqual(kwargs['params'], {
32+
'email': '[email protected]',
33+
'fields': 'a,b',
34+
'include_fields': 'false'
35+
})
36+
37+

0 commit comments

Comments
 (0)