Skip to content

Commit d606993

Browse files
authored
ENG-2608 - New APIs/method overloads (#51)
* capture current cli state * add report method * let's run on all PRs * forgot PHP * test/issue 1 * revert overloads * test fixes * client correct/optional * now that this overload does not have opt params, remove defaults
1 parent 05c846a commit d606993

3 files changed

Lines changed: 86 additions & 30 deletions

File tree

.github/workflows/test.yaml

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ on:
55
branches:
66
- main
77
pull_request:
8-
branches:
9-
- main
108
workflow_dispatch:
119

1210
permissions:
@@ -16,31 +14,31 @@ jobs:
1614
test:
1715
runs-on: ubuntu-latest
1816
steps:
19-
- uses: actions/checkout@v4
20-
21-
- name: Set up FusionAuth
22-
working-directory: .github/fusionauth
23-
run: docker compose up -d
24-
25-
- name: Validate composer.json and composer.lock
26-
run: |
27-
composer update
28-
composer validate
29-
30-
- name: Cache Composer packages
31-
id: composer-cache
32-
uses: actions/cache@v4
33-
with:
34-
path: vendor
35-
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
36-
restore-keys: |
37-
${{ runner.os }}-php-
38-
39-
- name: Install dependencies
40-
run: composer install --prefer-dist --no-progress
41-
42-
- name: Waiting for FusionAuth App
43-
run: timeout 30 bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost:9011)" != "200" ]]; do sleep 5; done' || false
44-
45-
- name: Run test suite
46-
run: composer run test
17+
- uses: actions/checkout@v4
18+
19+
- name: Set up FusionAuth
20+
working-directory: .github/fusionauth
21+
run: docker compose up -d
22+
23+
- name: Validate composer.json and composer.lock
24+
run: |
25+
composer update
26+
composer validate
27+
28+
- name: Cache Composer packages
29+
id: composer-cache
30+
uses: actions/cache@v4
31+
with:
32+
path: vendor
33+
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
34+
restore-keys: |
35+
${{ runner.os }}-php-
36+
37+
- name: Install dependencies
38+
run: composer install --prefer-dist --no-progress
39+
40+
- name: Waiting for FusionAuth App
41+
run: timeout 30 bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost:9011)" != "200" ]]; do sleep 5; done' || false
42+
43+
- name: Run test suite
44+
run: composer run test

src/FusionAuth/FusionAuthClient.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4392,6 +4392,24 @@ public function retrieveUserByLoginId($loginId)
43924392
->go();
43934393
}
43944394

4395+
/**
4396+
* Retrieves the user for the loginId, using specific loginIdTypes.
4397+
*
4398+
* @param string $loginId The email or username of the user.
4399+
* @param array $loginIdTypes the identity types that FusionAuth will compare the loginId to.
4400+
*
4401+
* @return ClientResponse The ClientResponse.
4402+
* @throws \Exception
4403+
*/
4404+
public function retrieveUserByLoginIdWithLoginIdTypes($loginId, $loginIdTypes)
4405+
{
4406+
return $this->start()->uri("/api/user")
4407+
->urlParameter("loginId", $loginId)
4408+
->urlParameter("loginIdTypes", $loginIdTypes)
4409+
->get()
4410+
->go();
4411+
}
4412+
43954413
/**
43964414
* Retrieves the user for the given username.
43974415
*
@@ -4621,6 +4639,31 @@ public function retrieveUserLoginReportByLoginId($applicationId, $loginId, $star
46214639
->go();
46224640
}
46234641

4642+
/**
4643+
* 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
4644+
* login counts for that application.
4645+
*
4646+
* @param string $applicationId (Optional) The application id.
4647+
* @param string $loginId The userId id.
4648+
* @param array $start The start instant as UTC milliseconds since Epoch.
4649+
* @param array $end The end instant as UTC milliseconds since Epoch.
4650+
* @param array $loginIdTypes the identity types that FusionAuth will compare the loginId to.
4651+
*
4652+
* @return ClientResponse The ClientResponse.
4653+
* @throws \Exception
4654+
*/
4655+
public function retrieveUserLoginReportByLoginIdAndLoginIdTypes($applicationId, $loginId, $start, $end, $loginIdTypes)
4656+
{
4657+
return $this->start()->uri("/api/report/login")
4658+
->urlParameter("applicationId", $applicationId)
4659+
->urlParameter("loginId", $loginId)
4660+
->urlParameter("start", $start)
4661+
->urlParameter("end", $end)
4662+
->urlParameter("loginIdTypes", $loginIdTypes)
4663+
->get()
4664+
->go();
4665+
}
4666+
46244667
/**
46254668
* Retrieves the last number of login records for a user.
46264669
*

tests/FusionAuth/FusionAuthClientTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,21 @@ public function testCanHandleUsers(): void
118118
$this->handleResponse($response);
119119
$this->assertEquals("test@fusionauth.io", $response->successResponse->user->email);
120120

121+
// retrieve by login Id (default types)
122+
$response = $this->client->retrieveUserByLoginId("test@fusionauth.io");
123+
$this->handleResponse($response);
124+
$this->assertEquals("test@fusionauth.io", $response->successResponse->user->email);
125+
126+
// retrieve by login Id (explicit types)
127+
$response = $this->client->retrieveUserByLoginIdWithLoginIdTypes("test@fusionauth.io", ["email"]);
128+
$this->handleResponse($response);
129+
$this->assertEquals("test@fusionauth.io", $response->successResponse->user->email);
130+
131+
// retrieve by login Id (not found, wrong type)
132+
// TODO: will pass once issue 1 is live
133+
// $response = $this->client->retrieveUserByLoginIdWithLoginIdTypes("test@fusionauth.io", ["phoneNumber"]);
134+
// $this->assertEquals(404, $response->status);
135+
121136
// Login
122137
$response = $this->client->login(["loginId" => "test@fusionauth.io", "password" => "password"]);
123138
$this->handleResponse($response);

0 commit comments

Comments
 (0)