diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 1df2db1..ba67e3e 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -10,9 +10,6 @@ on: - main - develop pull_request: - branches: - - main - - develop workflow_dispatch: jobs: diff --git a/src/main/python/fusionauth/fusionauth_client.py b/src/main/python/fusionauth/fusionauth_client.py index 264dc80..041efaf 100644 --- a/src/main/python/fusionauth/fusionauth_client.py +++ b/src/main/python/fusionauth/fusionauth_client.py @@ -3377,6 +3377,20 @@ def retrieve_user_by_login_id(self, login_id): .get() \ .go() + def retrieve_user_by_login_id_with_login_id_types(self, login_id, login_id_types): + """ + Retrieves the user for the loginId, using specific loginIdTypes. + + Attributes: + login_id: The email or username of the user. + login_id_types: the identity types that FusionAuth will compare the loginId to. + """ + return self.start().uri('/api/user') \ + .url_parameter('loginId', self.convert_true_false(login_id)) \ + .url_parameter('loginIdTypes', self.convert_true_false(login_id_types)) \ + .get() \ + .go() + def retrieve_user_by_username(self, username): """ Retrieves the user for the given username. @@ -3558,6 +3572,27 @@ def retrieve_user_login_report_by_login_id(self, login_id, start, end, applicati .get() \ .go() + def retrieve_user_login_report_by_login_id_and_login_id_types(self, login_id, start, end, login_id_types, application_id=None): + """ + Retrieves the login report between the two instants for a particular user by login Id, using specific loginIdTypes. If you specify an application id, it will only return the + login counts for that application. + + Attributes: + application_id: (Optional) The application id. + login_id: The userId id. + start: The start instant as UTC milliseconds since Epoch. + end: The end instant as UTC milliseconds since Epoch. + login_id_types: the identity types that FusionAuth will compare the loginId to. + """ + return self.start().uri('/api/report/login') \ + .url_parameter('applicationId', self.convert_true_false(application_id)) \ + .url_parameter('loginId', self.convert_true_false(login_id)) \ + .url_parameter('start', self.convert_true_false(start)) \ + .url_parameter('end', self.convert_true_false(end)) \ + .url_parameter('loginIdTypes', self.convert_true_false(login_id_types)) \ + .get() \ + .go() + def retrieve_user_recent_logins(self, user_id, offset, limit): """ Retrieves the last number of login records for a user. diff --git a/src/test/python/fusionauth/fusionauth_client_test.py b/src/test/python/fusionauth/fusionauth_client_test.py index dd72caf..8f7545c 100644 --- a/src/test/python/fusionauth/fusionauth_client_test.py +++ b/src/test/python/fusionauth/fusionauth_client_test.py @@ -1,4 +1,16 @@ -# Copyright (c) 2024, FusionAuth, All Rights Reserved +# Copyright (c) 2024-2025, FusionAuth, All Rights Reserved +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, +# either express or implied. See the License for the specific +# language governing permissions and limitations under the License. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -26,9 +38,8 @@ import json import os -import uuid - import unittest +import uuid from fusionauth.fusionauth_client import FusionAuthClient @@ -84,6 +95,25 @@ def test_create_user_retrieve_user(self): self.assertFalse('password' in get_user_response.success_response['user']) self.assertFalse('salt' in get_user_response.success_response['user']) + # Retrieve the user via loginId + get_user_response = self.client.retrieve_user_by_login_id('user@example.com') + self.assertEqual(get_user_response.status, 200) + self.assertIsNotNone(get_user_response.success_response) + self.assertIsNone(get_user_response.error_response) + self.assertEqual(get_user_response.success_response['user']['email'], 'user@example.com') + + # Explicit loginIdType + get_user_response = self.client.retrieve_user_by_login_id_with_login_id_types('user@example.com', ['email']) + self.assertEqual(get_user_response.status, 200) + self.assertIsNotNone(get_user_response.success_response) + self.assertIsNone(get_user_response.error_response) + self.assertEqual(get_user_response.success_response['user']['email'], 'user@example.com') + + # TODO: Once issue 1 is released, this test should pass + # # wrong loginIdType + # get_user_response = self.client.retrieve_user_by_login_id_with_login_id_types('user@example.com', ['phoneNumber']) + # self.assertEqual(get_user_response.status, 404) + def test_retrieve_user_missing(self): user_id = uuid.uuid4() client_response = self.client.retrieve_user(user_id)