Skip to content

Commit

Permalink
Merge branch 'master' into branding-theme
Browse files Browse the repository at this point in the history
  • Loading branch information
adamjmcgrath authored Mar 14, 2023
2 parents 8a84e23 + 1a1b975 commit 4a0cf84
Show file tree
Hide file tree
Showing 2 changed files with 170 additions and 0 deletions.
92 changes: 92 additions & 0 deletions auth0/management/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,3 +419,95 @@ def invalidate_remembered_browsers(self, user_id):

url = self._url(f"{user_id}/multifactor/actions/invalidate-remember-browser")
return self.client.post(url)

def get_authentication_methods(self, user_id):
"""Gets a list of authentication methods
Args:
user_id (str): The user_id to get a list of authentication methods for.
See: https://auth0.com/docs/api/management/v2#!/Users/get_authentication_methods
"""

url = self._url(f"{user_id}/authentication-methods")
return self.client.get(url)

def get_authentication_method_by_id(self, user_id, authentication_method_id):
"""Gets an authentication method by ID.
Args:
user_id (str): The user_id to get an authentication method by ID for.
authentication_method_id (str): The authentication_method_id to get an authentication method by ID for.
See: https://auth0.com/docs/api/management/v2#!/Users/get_authentication_methods_by_authentication_method_id
"""

url = self._url(f"{user_id}/authentication-methods/{authentication_method_id}")
return self.client.get(url)

def create_authentication_method(self, user_id, body):
"""Creates an authentication method for a given user.
Args:
user_id (str): The user_id to create an authentication method for a given user.
body (dict): the request body to create an authentication method for a given user.
See: https://auth0.com/docs/api/management/v2#!/Users/post_authentication_methods
"""

url = self._url(f"{user_id}/authentication-methods")
return self.client.post(url, data=body)

def update_authentication_methods(self, user_id, body):
"""Updates all authentication methods for a user by replacing them with the given ones.
Args:
user_id (str): The user_id to update all authentication methods for.
body (dict): the request body to update all authentication methods with.
See: https://auth0.com/docs/api/management/v2#!/Users/put_authentication_methods
"""

url = self._url(f"{user_id}/authentication-methods")
return self.client.put(url, data=body)

def update_authentication_method_by_id(
self, user_id, authentication_method_id, body
):
"""Updates an authentication method.
Args:
user_id (str): The user_id to update an authentication method.
authentication_method_id (str): The authentication_method_id to update an authentication method for.
body (dict): the request body to update an authentication method.
See: https://auth0.com/docs/api/management/v2#!/Users/patch_authentication_methods_by_authentication_method_id
"""

url = self._url(f"{user_id}/authentication-methods/{authentication_method_id}")
return self.client.patch(url, data=body)

def delete_authentication_methods(self, user_id):
"""Deletes all authentication methods for the given user.
Args:
user_id (str): The user_id to delete all authentication methods for the given user for.
See: https://auth0.com/docs/api/management/v2#!/Users/delete_authentication_methods
"""

url = self._url(f"{user_id}/authentication-methods")
return self.client.delete(url)

def delete_authentication_method_by_id(self, user_id, authentication_method_id):
"""Deletes an authentication method by ID.
Args:
user_id (str): The user_id to delete an authentication method by ID for.
authentication_method_id (str): The authentication_method_id to delete an authentication method by ID for.
See: https://auth0.com/docs/api/management/v2#!/Users/delete_authentication_methods_by_authentication_method_id
"""

url = self._url(f"{user_id}/authentication-methods/{authentication_method_id}")
return self.client.delete(url)
78 changes: 78 additions & 0 deletions auth0/test/management/test_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,3 +325,81 @@ def test_invalidate_remembered_browsers(self, mock_rc):
"https://domain/api/v2/users/user-id/multifactor/actions/invalidate-remember-browser",
args[0],
)

@mock.patch("auth0.management.users.RestClient")
def test_get_authentication_methods(self, mock_rc):
mock_instance = mock_rc.return_value

u = Users(domain="domain", token="jwttoken")
u.get_authentication_methods("user_id")

mock_instance.get.assert_called_with(
"https://domain/api/v2/users/user_id/authentication-methods"
)

@mock.patch("auth0.management.users.RestClient")
def test_get_authentication_method_by_id(self, mock_rc):
mock_instance = mock_rc.return_value

u = Users(domain="domain", token="jwttoken")
u.get_authentication_method_by_id("user_id", "authentication_method_id")

mock_instance.get.assert_called_with(
"https://domain/api/v2/users/user_id/authentication-methods/authentication_method_id"
)

@mock.patch("auth0.management.users.RestClient")
def test_create_authentication_method(self, mock_rc):
mock_instance = mock_rc.return_value

u = Users(domain="domain", token="jwttoken")
u.create_authentication_method("user_id", {})

mock_instance.post.assert_called_with(
"https://domain/api/v2/users/user_id/authentication-methods", data={}
)

@mock.patch("auth0.management.users.RestClient")
def test_update_authentication_methods(self, mock_rc):
mock_instance = mock_rc.return_value

u = Users(domain="domain", token="jwttoken")
u.update_authentication_methods("user_id", {})

mock_instance.put.assert_called_with(
"https://domain/api/v2/users/user_id/authentication-methods", data={}
)

@mock.patch("auth0.management.users.RestClient")
def test_update_authentication_method_by_id(self, mock_rc):
mock_instance = mock_rc.return_value

u = Users(domain="domain", token="jwttoken")
u.update_authentication_method_by_id("user_id", "authentication_method_id", {})

mock_instance.patch.assert_called_with(
"https://domain/api/v2/users/user_id/authentication-methods/authentication_method_id",
data={},
)

@mock.patch("auth0.management.users.RestClient")
def test_delete_authentication_methods(self, mock_rc):
mock_instance = mock_rc.return_value

u = Users(domain="domain", token="jwttoken")
u.delete_authentication_methods("user_id")

mock_instance.delete.assert_called_with(
"https://domain/api/v2/users/user_id/authentication-methods"
)

@mock.patch("auth0.management.users.RestClient")
def test_delete_authentication_method_by_id(self, mock_rc):
mock_instance = mock_rc.return_value

u = Users(domain="domain", token="jwttoken")
u.delete_authentication_method_by_id("user_id", "authentication_method_id")

mock_instance.delete.assert_called_with(
"https://domain/api/v2/users/user_id/authentication-methods/authentication_method_id"
)

0 comments on commit 4a0cf84

Please sign in to comment.