Skip to content

Commit ccdfa42

Browse files
authored
[SDK-2435] Add Organizations support to Management API Client (#483)
1 parent 1335f7d commit ccdfa42

File tree

11 files changed

+1984
-50
lines changed

11 files changed

+1984
-50
lines changed

phpunit.xml.dist

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
<phpunit
2-
colors="true"
3-
verbose="true"
4-
bootstrap="./tests/bootstrap.php">
1+
<?xml version="1.0"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true" verbose="true" bootstrap="./tests/bootstrap.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
3+
<coverage>
4+
<include>
5+
<directory suffix=".php">./src/</directory>
6+
</include>
7+
</coverage>
58
<testsuites>
69
<testsuite name="unit">
710
<directory>./tests/unit</directory>
@@ -10,10 +13,4 @@
1013
<directory>./tests/integration</directory>
1114
</testsuite>
1215
</testsuites>
13-
14-
<filter>
15-
<whitelist>
16-
<directory suffix=".php">./src/</directory>
17-
</whitelist>
18-
</filter>
1916
</phpunit>

src/API/Management.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Auth0\SDK\API\Management\Logs;
1919
use Auth0\SDK\API\Management\LogStreams;
2020
use Auth0\SDK\API\Management\ResourceServers;
21+
use Auth0\SDK\API\Management\Organizations;
2122
use Auth0\SDK\API\Management\Roles;
2223
use Auth0\SDK\API\Management\Rules;
2324
use Auth0\SDK\API\Management\Stats;
@@ -126,6 +127,13 @@ class Management
126127
*/
127128
private $logStreams;
128129

130+
/**
131+
* Instance of Auth0\SDK\API\Management\Organizations
132+
*
133+
* @var Organizations
134+
*/
135+
private $organizations;
136+
129137
/**
130138
* Instance of Auth0\SDK\API\Management\Roles
131139
*
@@ -381,6 +389,20 @@ public function logStreams() : LogStreams
381389
return $this->logStreams;
382390
}
383391

392+
/**
393+
* Return an instance of the Organizations class.
394+
*
395+
* @return Organizations
396+
*/
397+
public function organizations() : Organizations
398+
{
399+
if (! $this->organizations instanceof Organizations) {
400+
$this->organizations = new Organizations($this->apiClient);
401+
}
402+
403+
return $this->organizations;
404+
}
405+
384406
/**
385407
* Return an instance of the Roles class.
386408
*

src/API/Management/GenericResource.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,4 +183,21 @@ protected function checkEmptyOrInvalidString($var, $var_name)
183183
throw new EmptyOrInvalidParameterException($var_name);
184184
}
185185
}
186+
187+
/**
188+
* Check that a variable is an array and is not empty.
189+
*
190+
* @param mixed $var The variable to check.
191+
* @param string $var_name The variable name.
192+
*
193+
* @return void
194+
*
195+
* @throws EmptyOrInvalidParameterException If $var is empty or is not a string.
196+
*/
197+
protected function checkEmptyOrInvalidArray($var, $var_name)
198+
{
199+
if (! is_array($var) || ! count($var)) {
200+
throw new EmptyOrInvalidParameterException($var_name);
201+
}
202+
}
186203
}

src/API/Management/Jobs.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,11 @@ public function exportUsers($params = [])
125125
*
126126
* @param string $user_id User ID of the user to send the verification email to.
127127
* @param array $params Array of optional parameters to add.
128-
* - client_id: Client ID of the requesting application. If not provided, the global Client ID will be used.
129-
* - identity: The optional identity of the user, as an array. Required to verify primary identities when using social, enterprise, or passwordless connections. It is also required to verify secondary identities.
130-
* - user_id: User ID of the identity to be verified. Must be a non-empty string.
131-
* - provider: Identity provider name of the identity (e.g. google-oauth2). Must be a non-empty string.
128+
* - client_id: Client ID of the requesting application. If not provided, the global Client ID will be used.
129+
* - identity: The optional identity of the user, as an array. Required to verify primary identities when using social, enterprise, or passwordless connections. It is also required to verify secondary identities.
130+
* - user_id: User ID of the identity to be verified. Must be a non-empty string.
131+
* - provider: Identity provider name of the identity (e.g. google-oauth2). Must be a non-empty string.
132+
* - organization_id: ID of the organization. If provided, the organization_id and organization_name will be included as query arguments in the link back to the application.
132133
*
133134
* @throws EmptyOrInvalidParameterException Thrown if any required parameters are empty or invalid.
134135
* @throws \Exception Thrown by the HTTP client when there is a problem with the API call.
@@ -145,6 +146,10 @@ public function sendVerificationEmail($user_id, array $params = [])
145146
$body['client_id'] = $params['client_id'];
146147
}
147148

149+
if (! empty( $params['organization_id'] )) {
150+
$body['organization_id'] = $params['organization_id'];
151+
}
152+
148153
if (! empty( $params['identity'] )) {
149154
if (empty( $params['identity']['user_id']) || ! is_string($params['identity']['user_id'])) {
150155
throw new EmptyOrInvalidParameterException('Missing required "user_id" field of the "identity" object.');

0 commit comments

Comments
 (0)