Skip to content

ENG-2608 - New APIs/method overloads #41

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

Merged
merged 7 commits into from
May 7, 2025
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: 0 additions & 3 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ on:
- main
- develop
pull_request:
branches:
- main
- develop
workflow_dispatch:

jobs:
Expand Down
35 changes: 35 additions & 0 deletions src/main/python/fusionauth/fusionauth_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
36 changes: 33 additions & 3 deletions src/test/python/fusionauth/fusionauth_client_test.py
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -26,9 +38,8 @@

import json
import os
import uuid

import unittest
import uuid

from fusionauth.fusionauth_client import FusionAuthClient

Expand Down Expand Up @@ -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('[email protected]')
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'], '[email protected]')

# Explicit loginIdType
get_user_response = self.client.retrieve_user_by_login_id_with_login_id_types('[email protected]', ['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'], '[email protected]')

# 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('[email protected]', ['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)
Expand Down