Skip to content

Commit b79ca08

Browse files
committed
Add metadata and external id
And allow to be passed when creating or updating a user or organization.
1 parent ce73c88 commit b79ca08

File tree

6 files changed

+109
-23
lines changed

6 files changed

+109
-23
lines changed

lib/Organizations.php

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,22 @@ public function listOrganizations(
6767
* @param null|boolean $allowProfilesOutsideOrganization [Deprecated] If you need to allow sign-ins from
6868
* any email domain, contact support@workos.com.
6969
* @param null|string $idempotencyKey is a unique string that identifies a distinct organization
70+
* @param null|string $externalId The organization's external id
71+
* @param null|array<string, string> $metadata The organization's metadata
7072
*
7173
* @throws Exception\WorkOSException
7274
*
7375
* @return Resource\Organization
7476
*/
75-
public function createOrganization($name, $domains = null, $allowProfilesOutsideOrganization = null, $idempotencyKey = null, $domain_data = null)
76-
{
77+
public function createOrganization(
78+
$name,
79+
$domains = null,
80+
$allowProfilesOutsideOrganization = null,
81+
$idempotencyKey = null,
82+
$domain_data = null,
83+
$externalId = null,
84+
$metadata = null
85+
) {
7786
$idempotencyKey ? $headers = array("Idempotency-Key: $idempotencyKey") : $headers = null;
7887
$organizationsPath = "organizations";
7988

@@ -88,6 +97,12 @@ public function createOrganization($name, $domains = null, $allowProfilesOutside
8897
if (isset($allowProfilesOutsideOrganization)) {
8998
$params["allow_profiles_outside_organization"] = $allowProfilesOutsideOrganization;
9099
}
100+
if (isset($externalId)) {
101+
$params["external_id"] = $externalId;
102+
}
103+
if (isset($metadata)) {
104+
$params["metadata"] = $metadata;
105+
}
91106

92107
$response = Client::request(Client::METHOD_POST, $organizationsPath, $headers, $params, true);
93108

@@ -104,11 +119,21 @@ public function createOrganization($name, $domains = null, $allowProfilesOutside
104119
* @param null|boolean $allowProfilesOutsideOrganization [Deprecated] If you need to allow sign-ins from
105120
* any email domain, contact support@workos.com.
106121
* @param null|string $stripeCustomerId The Stripe Customer ID of the Organization.
122+
* @param null|string $externalId The organization's external id
123+
* @param null|array<string, string> $metadata The organization's metadata
107124
*
108125
* @throws Exception\WorkOSException
109126
*/
110-
public function updateOrganization($organization, $domains = null, $name = null, $allowProfilesOutsideOrganization = null, $domain_data = null, $stripeCustomerId = null)
111-
{
127+
public function updateOrganization(
128+
$organization,
129+
$domains = null,
130+
$name = null,
131+
$allowProfilesOutsideOrganization = null,
132+
$domain_data = null,
133+
$stripeCustomerId = null,
134+
$externalId = null,
135+
$metadata = null
136+
) {
112137
$organizationsPath = "organizations/{$organization}";
113138

114139
$params = [ "name" => $name ];
@@ -125,6 +150,12 @@ public function updateOrganization($organization, $domains = null, $name = null,
125150
if (isset($stripeCustomerId)) {
126151
$params["stripe_customer_id"] = $stripeCustomerId;
127152
}
153+
if (isset($externalId)) {
154+
$params["external_id"] = $externalId;
155+
}
156+
if (isset($metadata)) {
157+
$params["metadata"] = $metadata;
158+
}
128159

129160
$response = Client::request(Client::METHOD_PUT, $organizationsPath, null, $params, true);
130161

lib/Resource/Organization.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,17 @@ class Organization extends BaseWorkOSResource
1414
"id",
1515
"name",
1616
"allowProfilesOutsideOrganization",
17-
"domains"
17+
"domains",
18+
"externalId",
19+
"metadata"
1820
];
1921

2022
public const RESPONSE_TO_RESOURCE_KEY = [
2123
"id" => "id",
2224
"name" => "name",
2325
"allow_profiles_outside_organization" => "allowProfilesOutsideOrganization",
24-
"domains" => "domains"
26+
"domains" => "domains",
27+
"external_id" => "externalId",
28+
"metadata" => "metadata"
2529
];
2630
}

lib/Resource/User.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ class User extends BaseWorkOSResource
1919
"profilePictureUrl",
2020
"lastSignInAt",
2121
"createdAt",
22-
"updatedAt"
22+
"updatedAt",
23+
"externalId",
24+
"metadata"
2325
];
2426

2527
public const RESPONSE_TO_RESOURCE_KEY = [
@@ -32,6 +34,8 @@ class User extends BaseWorkOSResource
3234
"profile_picture_url" => "profilePictureUrl",
3335
"last_sign_in_at" => "lastSignInAt",
3436
"created_at" => "createdAt",
35-
"updated_at" => "updatedAt"
37+
"updated_at" => "updatedAt",
38+
"external_id" => "externalId",
39+
"metadata" => "metadata"
3640
];
3741
}

lib/UserManagement.php

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,24 @@ class UserManagement
2626
* @param boolean|null $emailVerified A boolean declaring if the user's email has been verified.
2727
* @param string|null $passwordHash The hashed password to set for the user.
2828
* @param string|null $passwordHashType The algorithm originally used to hash the password. Valid values are `bcrypt`, `ssha`, and `firebase-scrypt`.
29+
* @param string|null $externalId The user's external ID.
30+
* @param array<string, string> $metadata The user's metadata.
2931
*
3032
* @throws Exception\WorkOSException
3133
*
3234
* @return Resource\User
3335
*/
34-
public function createUser($email, $password = null, $firstName = null, $lastName = null, $emailVerified = null, $passwordHash = null, $passwordHashType = null)
35-
{
36+
public function createUser(
37+
$email,
38+
$password = null,
39+
$firstName = null,
40+
$lastName = null,
41+
$emailVerified = null,
42+
$passwordHash = null,
43+
$passwordHashType = null,
44+
$externalId = null,
45+
$metadata = null
46+
) {
3647
$path = "user_management/users";
3748
$params = [
3849
"email" => $email,
@@ -42,6 +53,8 @@ public function createUser($email, $password = null, $firstName = null, $lastNam
4253
"email_verified" => $emailVerified,
4354
"password_hash" => $passwordHash,
4455
"password_hash_type" => $passwordHashType,
56+
"external_id" => $externalId,
57+
"metadata" => $metadata
4558
];
4659

4760
$response = Client::request(Client::METHOD_POST, $path, null, $params, true);
@@ -77,6 +90,8 @@ public function getUser($userId)
7790
* @param string|null $password The password to set for the user.
7891
* @param string|null $passwordHash The hashed password to set for the user.
7992
* @param string|null $passwordHashType The algorithm originally used to hash the password. Valid values are `bcrypt`, `ssha`, and `firebase-scrypt`.
93+
* @param string|null $externalId The user's external ID.
94+
* @param array<string, string>|null $metadata The user's metadata.
8095
*
8196
* @throws Exception\WorkOSException
8297
*
@@ -89,7 +104,9 @@ public function updateUser(
89104
$emailVerified = null,
90105
$password = null,
91106
$passwordHash = null,
92-
$passwordHashType = null
107+
$passwordHashType = null,
108+
$externalId = null,
109+
$metadata = null
93110
) {
94111
$path = "user_management/users/{$userId}";
95112

@@ -100,6 +117,8 @@ public function updateUser(
100117
"password" => $password,
101118
"password_hash" => $passwordHash,
102119
"password_hash_type" => $passwordHashType,
120+
"external_id" => $externalId,
121+
"metadata" => $metadata
103122
];
104123

105124
$response = Client::request(Client::METHOD_PUT, $path, null, $params, true);

tests/WorkOS/OrganizationsTest.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,9 @@ private function createOrganizationResponseFixture()
205205
"id" => "org_domain_01EHQMYV71XT8H31WE5HF8YK4A",
206206
"domain" => "example.com"
207207
]
208-
]
208+
],
209+
"external_id" => null,
210+
"metadata" => []
209211
]);
210212
}
211213

@@ -225,7 +227,9 @@ private function organizationsResponseFixture()
225227
"id" => "org_domain_01EHQMYV71XT8H31WE5HF8YK4A",
226228
"domain" => "example.com"
227229
]
228-
]
230+
],
231+
"external_id" => null,
232+
"metadata" => []
229233
],
230234
[
231235
"object" => "organization",
@@ -238,7 +242,9 @@ private function organizationsResponseFixture()
238242
"id" => "org_domain_01EHQMVDTZVA27PK614ME4YK7V",
239243
"domain" => "example2.com"
240244
]
241-
]
245+
],
246+
"external_id" => null,
247+
"metadata" => []
242248
],
243249
[
244250
"object" => "organization",
@@ -251,7 +257,9 @@ private function organizationsResponseFixture()
251257
"id" => "org_domain_01EGP9Z6S6HVQ5CPD152GJBEA5",
252258
"domain" => "example5.com"
253259
]
254-
]
260+
],
261+
"external_id" => null,
262+
"metadata" => []
255263
]
256264
],
257265
"list_metadata" => [
@@ -273,7 +281,9 @@ private function organizationFixture()
273281
"id" => "org_domain_01EHQMYV71XT8H31WE5HF8YK4A",
274282
"domain" => "example.com"
275283
]
276-
]
284+
],
285+
"externalId" => null,
286+
"metadata" => []
277287
];
278288
}
279289

tests/WorkOS/UserManagementTest.php

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ public function testUpdateUser()
5555
"password" => null,
5656
"password_hash" => null,
5757
"password_hash_type" => null,
58+
"external_id" => null,
59+
"metadata" => null
5860
];
5961

6062
$this->mockRequest(
@@ -481,6 +483,8 @@ public function testCreateUser()
481483
"email_verified" => true,
482484
"password_hash" => null,
483485
"password_hash_type" => null,
486+
"external_id" => null,
487+
"metadata" => null
484488
];
485489

486490
$this->mockRequest(
@@ -1442,7 +1446,9 @@ private function userResponseFixture()
14421446
"profile_picture_url" => "https://example.com/photo.jpg",
14431447
"last_sign_in_at" => "2021-06-25T19:07:33.155Z",
14441448
"created_at" => "2021-06-25T19:07:33.155Z",
1445-
"updated_at" => "2021-06-25T19:07:33.155Z"
1449+
"updated_at" => "2021-06-25T19:07:33.155Z",
1450+
"external_id" => null,
1451+
"metadata" => []
14461452
]
14471453
]);
14481454
}
@@ -1460,7 +1466,9 @@ private function userAndImpersonatorResponseFixture()
14601466
"profile_picture_url" => "https://example.com/photo.jpg",
14611467
"last_sign_in_at" => "2021-06-25T19:07:33.155Z",
14621468
"created_at" => "2021-06-25T19:07:33.155Z",
1463-
"updated_at" => "2021-06-25T19:07:33.155Z"
1469+
"updated_at" => "2021-06-25T19:07:33.155Z",
1470+
"external_id" => null,
1471+
"metadata" => []
14641472
],
14651473
"impersonator" => [
14661474
"email" => "admin@foocorp.com",
@@ -1500,7 +1508,9 @@ private function createUserResponseFixture()
15001508
'profile_picture_url' => 'https://example.com/photo.jpg',
15011509
"last_sign_in_at" => "2021-06-25T19:07:33.155Z",
15021510
"created_at" => "2021-06-25T19:07:33.155Z",
1503-
"updated_at" => "2021-06-25T19:07:33.155Z"
1511+
"updated_at" => "2021-06-25T19:07:33.155Z",
1512+
"external_id" => null,
1513+
"metadata" => []
15041514
]);
15051515
}
15061516

@@ -1608,7 +1618,9 @@ private function getUserResponseFixture()
16081618
"profile_picture_url" => "https://example.com/photo.jpg",
16091619
"last_sign_in_at" => "2021-06-25T19:07:33.155Z",
16101620
"created_at" => "2021-06-25T19:07:33.155Z",
1611-
"updated_at" => "2021-06-25T19:07:33.155Z"
1621+
"updated_at" => "2021-06-25T19:07:33.155Z",
1622+
"external_id" => null,
1623+
"metadata" => []
16121624
]);
16131625
}
16141626

@@ -1626,7 +1638,9 @@ private function listUsersResponseFixture()
16261638
"profile_picture_url" => "https://example.com/photo.jpg",
16271639
"last_sign_in_at" => "2021-06-25T19:07:33.155Z",
16281640
"created_at" => "2021-06-25T19:07:33.155Z",
1629-
"updated_at" => "2021-06-25T19:07:33.155Z"
1641+
"updated_at" => "2021-06-25T19:07:33.155Z",
1642+
"external_id" => null,
1643+
"metadata" => []
16301644
]
16311645
],
16321646
"list_metadata" => [
@@ -1656,7 +1670,9 @@ private function userFixture()
16561670
"profilePictureUrl" => "https://example.com/photo.jpg",
16571671
"lastSignInAt" => "2021-06-25T19:07:33.155Z",
16581672
"createdAt" => "2021-06-25T19:07:33.155Z",
1659-
"updatedAt" => "2021-06-25T19:07:33.155Z"
1673+
"updatedAt" => "2021-06-25T19:07:33.155Z",
1674+
"externalId" => null,
1675+
"metadata" => []
16601676
];
16611677
}
16621678

@@ -1673,7 +1689,9 @@ private function userAndOrgResponseFixture()
16731689
"profile_picture_url" => "https://example.com/photo.jpg",
16741690
"last_sign_in_at" => "2021-06-25T19:07:33.155Z",
16751691
"created_at" => "2021-06-25T19:07:33.155Z",
1676-
"updated_at" => "2021-06-25T19:07:33.155Z"
1692+
"updated_at" => "2021-06-25T19:07:33.155Z",
1693+
"external_id" => null,
1694+
"metadata" => []
16771695
],
16781696
"organization_id" => "org_01EHQMYV6MBK39QC5PZXHY59C3",
16791697
]);

0 commit comments

Comments
 (0)