Skip to content

Commit

Permalink
Support For PhoneNumber as a flexible identifier
Browse files Browse the repository at this point in the history
  • Loading branch information
kishore7snehil committed Jan 15, 2025
1 parent f54ca47 commit 68799b9
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/API/Authentication.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ public function dbConnectionsChangePassword(
'client_id' => $this->getConfiguration()->getClientId(ConfigurationException::requiresClientId()),
'email' => $email,
'connection' => $connection,
'phone_number' => $body['phone_number'] ?? null,
], $body]))
->withHeaders($headers)
->call();
Expand Down Expand Up @@ -170,6 +171,7 @@ public function dbConnectionsSignup(
'email' => $email,
'password' => $password,
'connection' => $connection,
'phone_number' => $body['phone_number'] ?? null,
], $body]))
->withHeaders($headers)
->call();
Expand Down
73 changes: 73 additions & 0 deletions tests/Unit/API/AuthenticationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,52 @@
expect($requestHeaders['header_testing'][0])->toEqual(123);
});

test('dbConnectionsSignup handles phone_number correctly', function (): void {
$clientSecret = uniqid();
$email = 'someone@somewhere.somehow';
$password = uniqid();
$connection = uniqid();
$phoneNumber = '+1234567890';

$this->configuration->setClientSecret($clientSecret);
$authentication = $this->sdk->authentication();
$authentication->getHttpClient()->mockResponses([HttpResponseGenerator::create()]);

// Test with phone_number
$authentication->dbConnectionsSignup($email, $password, $connection, ['phone_number' => $phoneNumber]);
$requestWithPhone = $authentication->getHttpClient()->getLastRequest()->getLastRequest();
$requestBodyWithPhone = json_decode($requestWithPhone->getBody()->__toString(), true);

$this->assertArrayHasKey('phone_number', $requestBodyWithPhone);
expect($requestBodyWithPhone['phone_number'])->toEqual($phoneNumber);

// Test without phone_number
$authentication->dbConnectionsSignup($email, $password, $connection);
$requestWithoutPhone = $authentication->getHttpClient()->getLastRequest()->getLastRequest();
$requestBodyWithoutPhone = json_decode($requestWithoutPhone->getBody()->__toString(), true);

$this->assertArrayNotHasKey('phone_number', $requestBodyWithoutPhone);
});

test('dbConnectionsSignup handles flexible identifiers and precedence', function (): void {
$clientSecret = uniqid();
$email = 'someone@somewhere.somehow';
$password = uniqid();
$connection = uniqid();
$phoneNumber = '+1234567890';

$this->configuration->setClientSecret($clientSecret);
$authentication = $this->sdk->authentication();
$authentication->getHttpClient()->mockResponses([HttpResponseGenerator::create()]);

$authentication->dbConnectionsSignup($email, $password, $connection, ['phone_number' => $phoneNumber]);
$request = $authentication->getHttpClient()->getLastRequest()->getLastRequest();
$requestBody = json_decode($request->getBody()->__toString(), true);

expect($requestBody['email'])->toEqual($email);
expect($requestBody['phone_number'])->toEqual($phoneNumber);
});

test('dbConnectionsChangePassword() is properly formatted', function(): void {
$clientSecret = uniqid();

Expand Down Expand Up @@ -587,6 +633,33 @@
expect($requestHeaders['header_testing'][0])->toEqual(123);
});

test('dbConnectionsChangePassword handles phone_number correctly', function (): void {
$clientSecret = uniqid();

$email = 'someone@somewhere.somehow';
$connection = uniqid();
$phoneNumber = '+1234567890';

$this->configuration->setClientSecret($clientSecret);
$authentication = $this->sdk->authentication();
$authentication->getHttpClient()->mockResponses([HttpResponseGenerator::create()]);

// Test with phone_number
$authentication->dbConnectionsChangePassword($email, $connection, ['phone_number' => $phoneNumber]);
$requestWithPhone = $authentication->getHttpClient()->getLastRequest()->getLastRequest();
$requestBodyWithPhone = json_decode($requestWithPhone->getBody()->__toString(), true);

$this->assertArrayHasKey('phone_number', $requestBodyWithPhone);
expect($requestBodyWithPhone['phone_number'])->toEqual($phoneNumber);

// Test without phone_number
$authentication->dbConnectionsChangePassword($email, $connection);
$requestWithoutPhone = $authentication->getHttpClient()->getLastRequest()->getLastRequest();
$requestBodyWithoutPhone = json_decode($requestWithoutPhone->getBody()->__toString(), true);

$this->assertArrayNotHasKey('phone_number', $requestBodyWithoutPhone);
});

test('pushedAuthorizationRequest() returns an instance of Auth0\SDK\API\Authentication\PushedAuthorizationRequest', function () {
$authentication = $this->sdk->authentication();
$pushedAuthorizationRequest = $authentication->pushedAuthorizationRequest();
Expand Down

0 comments on commit 68799b9

Please sign in to comment.