Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,9 @@ Available Management Endpoints
- Stats() ( ``Auth0().stats`` )
- Tenants() ( ``Auth0().tenants`` )
- Tickets() ( ``Auth0().tickets`` )
- Users() ( ``Auth0().users`` )
- UserBlocks() (``Auth0().user_blocks`` )
- Users() ( ``Auth0().users`` )
- UsersByEmail() ( ``Auth0().users_by_email`` )

Available Authentication Endpoints
==================================
Expand Down
3 changes: 2 additions & 1 deletion auth0/v3/management/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
from .stats import Stats
from .tenants import Tenants
from .tickets import Tickets
from .user_blocks import UserBlocks
from .users import Users
from .user_blocks import UserBlocks
from .users_by_email import UsersByEmail
6 changes: 4 additions & 2 deletions auth0/v3/management/auth0.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
from .stats import Stats
from .tenants import Tenants
from .tickets import Tickets
from .users import Users
from .user_blocks import UserBlocks
from .users import Users
from .users_by_email import UsersByEmail

class Auth0(object):
"""Provides easy access to all endpoint classes
Expand All @@ -41,5 +42,6 @@ def __init__(self, domain, token):
self.stats = Stats(domain, token)
self.tenants = Tenants(domain, token)
self.tickets = Tickets(domain, token)
self.users = Users(domain, token)
self.user_blocks = UserBlocks(domain, token)
self.users = Users(domain, token)
self.users_by_email = UsersByEmail(domain, token)
44 changes: 44 additions & 0 deletions auth0/v3/management/users_by_email.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from .rest import RestClient


class UsersByEmail(object):

"""Auth0 users by email endpoints

Args:
domain (str): Your Auth0 domain, e.g: 'username.auth0.com'

token (str): Management API v2 Token

telemetry (bool, optional): Enable or disable Telemetry
(defaults to True)
"""

def __init__(self, domain, token, telemetry=True):
self.domain = domain
self.client = RestClient(jwt=token, telemetry=telemetry)

def _url(self):
url = 'https://%s/api/v2/users-by-email' % self.domain
return url

def search_users_by_email(self, email, fields=None, include_fields=True):
"""List or search users.

Args:

email: Email to search

fields (list of str, optional): A list of fields to include or
exclude from the result (depending on include_fields). Empty to
retrieve all fields.

include_fields (bool, optional): True if the fields specified are
to be include in the result, False otherwise.
"""
params = {
'email': email.lower(),
'fields': fields and ','.join(fields) or None,
'include_fields': str(include_fields).lower()
}
return self.client.get(self._url(), params=params)
37 changes: 37 additions & 0 deletions auth0/v3/test/management/test_users_by_email.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import unittest
import mock
from ...management.users_by_email import UsersByEmail


class TestUsersByEmail(unittest.TestCase):

@mock.patch('auth0.v3.management.users_by_email.RestClient')
def test_search_users_by_email(self, mock_rc):
mock_instance = mock_rc.return_value

u = UsersByEmail(domain='domain', token='jwttoken')
u.search_users_by_email('A@B.com')

args, kwargs = mock_instance.get.call_args

self.assertEqual('https://domain/api/v2/users-by-email', args[0])
self.assertEqual(kwargs['params'], {
'email': 'a@b.com',
'fields': None,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean that there's a field=null parameter being sent on the body?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes we set this parameter to None before sending it, if the field array is empty on this line.

'include_fields': 'true'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is probably no harm, but why sending this if no fields where passed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made a quick test and setting the field to True or False makes no harm if fields array is not sent. I had copied this behaviour from list API.

})

u.search_users_by_email(email='a@b.com',
fields=['a', 'b'],
include_fields=False)

args, kwargs = mock_instance.get.call_args

self.assertEqual('https://domain/api/v2/users-by-email', args[0])
self.assertEqual(kwargs['params'], {
'email': 'a@b.com',
'fields': 'a,b',
'include_fields': 'false'
})