Skip to content

Commit 8ae123b

Browse files
Auth API - Support For PhoneNumber as a flexible identifier (#787)
### Changes Added phone number as a flexible optional identifier for following endpoints: - [Sign Up](https://auth0.com/docs/api/authentication#signup) - [Change Password](https://auth0.com/docs/api/authentication#change-password) ### References - Internal API Change Docs ### Testing - [x] This change adds test coverage - [x] This change has been tested on the latest version of the platform/language or why not ### Contributor Checklist - [x] I agree to adhere to the [Auth0 General Contribution Guidelines](https://github.com/auth0/open-source-template/blob/master/GENERAL-CONTRIBUTING.md). - [x] I agree to uphold the [Auth0 Code of Conduct](https://github.com/auth0/open-source-template/blob/master/CODE-OF-CONDUCT.md).
1 parent f54ca47 commit 8ae123b

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed

src/API/Authentication.php

+2
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ public function dbConnectionsChangePassword(
139139
'client_id' => $this->getConfiguration()->getClientId(ConfigurationException::requiresClientId()),
140140
'email' => $email,
141141
'connection' => $connection,
142+
'phone_number' => $body['phone_number'] ?? null,
142143
], $body]))
143144
->withHeaders($headers)
144145
->call();
@@ -170,6 +171,7 @@ public function dbConnectionsSignup(
170171
'email' => $email,
171172
'password' => $password,
172173
'connection' => $connection,
174+
'phone_number' => $body['phone_number'] ?? null,
173175
], $body]))
174176
->withHeaders($headers)
175177
->call();

tests/Unit/API/AuthenticationTest.php

+73
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,52 @@
554554
expect($requestHeaders['header_testing'][0])->toEqual(123);
555555
});
556556

557+
test('dbConnectionsSignup handles phone_number correctly', function (): void {
558+
$clientSecret = uniqid();
559+
$email = '[email protected]';
560+
$password = uniqid();
561+
$connection = uniqid();
562+
$phoneNumber = '+1234567890';
563+
564+
$this->configuration->setClientSecret($clientSecret);
565+
$authentication = $this->sdk->authentication();
566+
$authentication->getHttpClient()->mockResponses([HttpResponseGenerator::create()]);
567+
568+
// Test with phone_number
569+
$authentication->dbConnectionsSignup($email, $password, $connection, ['phone_number' => $phoneNumber]);
570+
$requestWithPhone = $authentication->getHttpClient()->getLastRequest()->getLastRequest();
571+
$requestBodyWithPhone = json_decode($requestWithPhone->getBody()->__toString(), true);
572+
573+
$this->assertArrayHasKey('phone_number', $requestBodyWithPhone);
574+
expect($requestBodyWithPhone['phone_number'])->toEqual($phoneNumber);
575+
576+
// Test without phone_number
577+
$authentication->dbConnectionsSignup($email, $password, $connection);
578+
$requestWithoutPhone = $authentication->getHttpClient()->getLastRequest()->getLastRequest();
579+
$requestBodyWithoutPhone = json_decode($requestWithoutPhone->getBody()->__toString(), true);
580+
581+
$this->assertArrayNotHasKey('phone_number', $requestBodyWithoutPhone);
582+
});
583+
584+
test('dbConnectionsSignup handles flexible identifiers and precedence', function (): void {
585+
$clientSecret = uniqid();
586+
$email = '[email protected]';
587+
$password = uniqid();
588+
$connection = uniqid();
589+
$phoneNumber = '+1234567890';
590+
591+
$this->configuration->setClientSecret($clientSecret);
592+
$authentication = $this->sdk->authentication();
593+
$authentication->getHttpClient()->mockResponses([HttpResponseGenerator::create()]);
594+
595+
$authentication->dbConnectionsSignup($email, $password, $connection, ['phone_number' => $phoneNumber]);
596+
$request = $authentication->getHttpClient()->getLastRequest()->getLastRequest();
597+
$requestBody = json_decode($request->getBody()->__toString(), true);
598+
599+
expect($requestBody['email'])->toEqual($email);
600+
expect($requestBody['phone_number'])->toEqual($phoneNumber);
601+
});
602+
557603
test('dbConnectionsChangePassword() is properly formatted', function(): void {
558604
$clientSecret = uniqid();
559605

@@ -587,6 +633,33 @@
587633
expect($requestHeaders['header_testing'][0])->toEqual(123);
588634
});
589635

636+
test('dbConnectionsChangePassword handles phone_number correctly', function (): void {
637+
$clientSecret = uniqid();
638+
639+
$email = '[email protected]';
640+
$connection = uniqid();
641+
$phoneNumber = '+1234567890';
642+
643+
$this->configuration->setClientSecret($clientSecret);
644+
$authentication = $this->sdk->authentication();
645+
$authentication->getHttpClient()->mockResponses([HttpResponseGenerator::create()]);
646+
647+
// Test with phone_number
648+
$authentication->dbConnectionsChangePassword($email, $connection, ['phone_number' => $phoneNumber]);
649+
$requestWithPhone = $authentication->getHttpClient()->getLastRequest()->getLastRequest();
650+
$requestBodyWithPhone = json_decode($requestWithPhone->getBody()->__toString(), true);
651+
652+
$this->assertArrayHasKey('phone_number', $requestBodyWithPhone);
653+
expect($requestBodyWithPhone['phone_number'])->toEqual($phoneNumber);
654+
655+
// Test without phone_number
656+
$authentication->dbConnectionsChangePassword($email, $connection);
657+
$requestWithoutPhone = $authentication->getHttpClient()->getLastRequest()->getLastRequest();
658+
$requestBodyWithoutPhone = json_decode($requestWithoutPhone->getBody()->__toString(), true);
659+
660+
$this->assertArrayNotHasKey('phone_number', $requestBodyWithoutPhone);
661+
});
662+
590663
test('pushedAuthorizationRequest() returns an instance of Auth0\SDK\API\Authentication\PushedAuthorizationRequest', function () {
591664
$authentication = $this->sdk->authentication();
592665
$pushedAuthorizationRequest = $authentication->pushedAuthorizationRequest();

0 commit comments

Comments
 (0)