-
Notifications
You must be signed in to change notification settings - Fork 183
Add GET Users-by-email to the Management API #96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
c07d34d
58c0163
5343fd8
0e8c4a1
3b0737b
8b205c2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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) |
| 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, | ||
| 'include_fields': 'true' | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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' | ||
| }) | ||
|
|
||
|
|
||
There was a problem hiding this comment.
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=nullparameter being sent on the body?There was a problem hiding this comment.
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.