-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathUserManagement.php
More file actions
1437 lines (1374 loc) · 59.1 KB
/
UserManagement.php
File metadata and controls
1437 lines (1374 loc) · 59.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
declare(strict_types=1);
// This file is auto-generated by oagen. Do not edit.
namespace WorkOS\Service;
use WorkOS\Resource\AuthenticateResponse;
use WorkOS\Resource\AuthorizedConnectApplicationListData;
use WorkOS\Resource\CORSOriginResponse;
use WorkOS\Resource\DeviceAuthorizationResponse;
use WorkOS\Resource\EmailChange;
use WorkOS\Resource\EmailChangeConfirmation;
use WorkOS\Resource\EmailVerification;
use WorkOS\Resource\Invitation;
use WorkOS\Resource\JwksResponse;
use WorkOS\Resource\JWTTemplateResponse;
use WorkOS\Resource\MagicAuth;
use WorkOS\Resource\OrganizationMembership;
use WorkOS\Resource\PasswordReset;
use WorkOS\Resource\RedirectUri;
use WorkOS\Resource\ResetPasswordResponse;
use WorkOS\Resource\SendVerificationEmailResponse;
use WorkOS\Resource\User;
use WorkOS\Resource\UserIdentitiesGetItem;
use WorkOS\Resource\UserInvite;
use WorkOS\Resource\UserOrganizationMembership;
use WorkOS\Resource\UserSessionsListItem;
use WorkOS\Resource\VerifyEmailResponse;
class UserManagement
{
public function __construct(
private readonly \WorkOS\HttpClient $client,
) {
}
/**
* Get JWKS
*
* Returns the JSON Web Key Set (JWKS) containing the public keys used for verifying access tokens.
* @param string $clientId Identifies the application making the request to the WorkOS server. You can obtain your client ID from the [API Keys](https://dashboard.workos.com/api-keys) page in the dashboard.
* @return \WorkOS\Resource\JwksResponse
*/
public function getJwks(
string $clientId,
?\WorkOS\RequestOptions $options = null,
): \WorkOS\Resource\JwksResponse {
$response = $this->client->request(
method: 'GET',
path: "sso/jwks/{$clientId}",
options: $options,
);
return JwksResponse::fromArray($response);
}
/**
* @param string $email
* @param string $password
* @param string|null $invitationToken
* @param string|null $ipAddress
* @param string|null $deviceId
* @param string|null $userAgent
* @return \WorkOS\Resource\AuthenticateResponse
*/
public function authenticateWithPassword(
string $email,
string $password,
?string $invitationToken = null,
?string $ipAddress = null,
?string $deviceId = null,
?string $userAgent = null,
?\WorkOS\RequestOptions $options = null,
): \WorkOS\Resource\AuthenticateResponse {
$body = array_filter([
'grant_type' => 'password',
'email' => $email,
'password' => $password,
'invitation_token' => $invitationToken,
'ip_address' => $ipAddress,
'device_id' => $deviceId,
'user_agent' => $userAgent,
], fn ($v) => $v !== null);
$body['client_id'] = $this->client->requireClientId();
$body['client_secret'] = $this->client->requireApiKey();
$response = $this->client->request(
method: 'POST',
path: 'user_management/authenticate',
body: $body,
options: $options,
);
return AuthenticateResponse::fromArray($response);
}
/**
* @param mixed $code
* @param mixed|null $ipAddress
* @param mixed|null $deviceId
* @param mixed|null $userAgent
* @return \WorkOS\Resource\AuthenticateResponse
*/
public function authenticateWithCode(
mixed $code = null,
mixed $ipAddress = null,
mixed $deviceId = null,
mixed $userAgent = null,
?\WorkOS\RequestOptions $options = null,
): \WorkOS\Resource\AuthenticateResponse {
$body = array_filter([
'grant_type' => 'authorization_code',
'code' => $code,
'ip_address' => $ipAddress,
'device_id' => $deviceId,
'user_agent' => $userAgent,
], fn ($v) => $v !== null);
$body['client_id'] = $this->client->requireClientId();
$body['client_secret'] = $this->client->requireApiKey();
$response = $this->client->request(
method: 'POST',
path: 'user_management/authenticate',
body: $body,
options: $options,
);
return AuthenticateResponse::fromArray($response);
}
/**
* @param string $refreshToken
* @param string|null $organizationId
* @param string|null $ipAddress
* @param string|null $deviceId
* @param string|null $userAgent
* @return \WorkOS\Resource\AuthenticateResponse
*/
public function authenticateWithRefreshToken(
string $refreshToken,
?string $organizationId = null,
?string $ipAddress = null,
?string $deviceId = null,
?string $userAgent = null,
?\WorkOS\RequestOptions $options = null,
): \WorkOS\Resource\AuthenticateResponse {
$body = array_filter([
'grant_type' => 'refresh_token',
'refresh_token' => $refreshToken,
'organization_id' => $organizationId,
'ip_address' => $ipAddress,
'device_id' => $deviceId,
'user_agent' => $userAgent,
], fn ($v) => $v !== null);
$body['client_id'] = $this->client->requireClientId();
$body['client_secret'] = $this->client->requireApiKey();
$response = $this->client->request(
method: 'POST',
path: 'user_management/authenticate',
body: $body,
options: $options,
);
return AuthenticateResponse::fromArray($response);
}
/**
* @param mixed $code
* @param mixed $email
* @param mixed|null $invitationToken
* @param mixed|null $ipAddress
* @param mixed|null $deviceId
* @param mixed|null $userAgent
* @return \WorkOS\Resource\AuthenticateResponse
*/
public function authenticateWithMagicAuth(
mixed $code = null,
mixed $email = null,
mixed $invitationToken = null,
mixed $ipAddress = null,
mixed $deviceId = null,
mixed $userAgent = null,
?\WorkOS\RequestOptions $options = null,
): \WorkOS\Resource\AuthenticateResponse {
$body = array_filter([
'grant_type' => 'urn:workos:oauth:grant-type:magic-auth:code',
'code' => $code,
'email' => $email,
'invitation_token' => $invitationToken,
'ip_address' => $ipAddress,
'device_id' => $deviceId,
'user_agent' => $userAgent,
], fn ($v) => $v !== null);
$body['client_id'] = $this->client->requireClientId();
$body['client_secret'] = $this->client->requireApiKey();
$response = $this->client->request(
method: 'POST',
path: 'user_management/authenticate',
body: $body,
options: $options,
);
return AuthenticateResponse::fromArray($response);
}
/**
* @param mixed $code
* @param mixed|null $pendingAuthenticationToken
* @param mixed|null $ipAddress
* @param mixed|null $deviceId
* @param mixed|null $userAgent
* @return \WorkOS\Resource\AuthenticateResponse
*/
public function authenticateWithEmailVerification(
mixed $code = null,
mixed $pendingAuthenticationToken = null,
mixed $ipAddress = null,
mixed $deviceId = null,
mixed $userAgent = null,
?\WorkOS\RequestOptions $options = null,
): \WorkOS\Resource\AuthenticateResponse {
$body = array_filter([
'grant_type' => 'urn:workos:oauth:grant-type:email-verification:code',
'code' => $code,
'pending_authentication_token' => $pendingAuthenticationToken,
'ip_address' => $ipAddress,
'device_id' => $deviceId,
'user_agent' => $userAgent,
], fn ($v) => $v !== null);
$body['client_id'] = $this->client->requireClientId();
$body['client_secret'] = $this->client->requireApiKey();
$response = $this->client->request(
method: 'POST',
path: 'user_management/authenticate',
body: $body,
options: $options,
);
return AuthenticateResponse::fromArray($response);
}
/**
* @param mixed $code
* @param mixed $pendingAuthenticationToken
* @param mixed $authenticationChallengeId
* @param mixed|null $ipAddress
* @param mixed|null $deviceId
* @param mixed|null $userAgent
* @return \WorkOS\Resource\AuthenticateResponse
*/
public function authenticateWithTotp(
mixed $code = null,
mixed $pendingAuthenticationToken = null,
mixed $authenticationChallengeId = null,
mixed $ipAddress = null,
mixed $deviceId = null,
mixed $userAgent = null,
?\WorkOS\RequestOptions $options = null,
): \WorkOS\Resource\AuthenticateResponse {
$body = array_filter([
'grant_type' => 'urn:workos:oauth:grant-type:mfa-totp',
'code' => $code,
'pending_authentication_token' => $pendingAuthenticationToken,
'authentication_challenge_id' => $authenticationChallengeId,
'ip_address' => $ipAddress,
'device_id' => $deviceId,
'user_agent' => $userAgent,
], fn ($v) => $v !== null);
$body['client_id'] = $this->client->requireClientId();
$body['client_secret'] = $this->client->requireApiKey();
$response = $this->client->request(
method: 'POST',
path: 'user_management/authenticate',
body: $body,
options: $options,
);
return AuthenticateResponse::fromArray($response);
}
/**
* @param mixed $pendingAuthenticationToken
* @param mixed $organizationId
* @param mixed|null $ipAddress
* @param mixed|null $deviceId
* @param mixed|null $userAgent
* @return \WorkOS\Resource\AuthenticateResponse
*/
public function authenticateWithOrganizationSelection(
mixed $pendingAuthenticationToken = null,
mixed $organizationId = null,
mixed $ipAddress = null,
mixed $deviceId = null,
mixed $userAgent = null,
?\WorkOS\RequestOptions $options = null,
): \WorkOS\Resource\AuthenticateResponse {
$body = array_filter([
'grant_type' => 'urn:workos:oauth:grant-type:organization-selection',
'pending_authentication_token' => $pendingAuthenticationToken,
'organization_id' => $organizationId,
'ip_address' => $ipAddress,
'device_id' => $deviceId,
'user_agent' => $userAgent,
], fn ($v) => $v !== null);
$body['client_id'] = $this->client->requireClientId();
$body['client_secret'] = $this->client->requireApiKey();
$response = $this->client->request(
method: 'POST',
path: 'user_management/authenticate',
body: $body,
options: $options,
);
return AuthenticateResponse::fromArray($response);
}
/**
* @param mixed $deviceCode
* @param mixed|null $ipAddress
* @param mixed|null $deviceId
* @param mixed|null $userAgent
* @return \WorkOS\Resource\AuthenticateResponse
*/
public function authenticateWithDeviceCode(
mixed $deviceCode = null,
mixed $ipAddress = null,
mixed $deviceId = null,
mixed $userAgent = null,
?\WorkOS\RequestOptions $options = null,
): \WorkOS\Resource\AuthenticateResponse {
$body = array_filter([
'grant_type' => 'urn:ietf:params:oauth:grant-type:device_code',
'device_code' => $deviceCode,
'ip_address' => $ipAddress,
'device_id' => $deviceId,
'user_agent' => $userAgent,
], fn ($v) => $v !== null);
$body['client_id'] = $this->client->requireClientId();
$response = $this->client->request(
method: 'POST',
path: 'user_management/authenticate',
body: $body,
options: $options,
);
return AuthenticateResponse::fromArray($response);
}
/**
* Get an authorization URL
*
* Generates an OAuth 2.0 authorization URL to authenticate a user with AuthKit or SSO.
* @param string|null $codeChallengeMethod The only valid PKCE code challenge method is `"S256"`. Required when specifying a `code_challenge`.
* @param string|null $codeChallenge Code challenge derived from the code verifier used for the PKCE flow.
* @param string|null $domainHint A domain hint for SSO connection lookup.
* @param string|null $connectionId The ID of an SSO connection to use for authentication.
* @param array<string, string>|null $providerQueryParams Key/value pairs of query parameters to pass to the OAuth provider.
* @param array<string>|null $providerScopes Additional OAuth scopes to request from the identity provider.
* @param string|null $invitationToken A token representing a user invitation to redeem during authentication.
* @param \WorkOS\Resource\UserManagementAuthenticationScreenHint|null $screenHint Used to specify which screen to display when the provider is `authkit`. Defaults to "sign-in".
* @param string|null $loginHint A hint to the authorization server about the login identifier the user might use.
* @param \WorkOS\Resource\UserManagementAuthenticationProvider|null $provider The OAuth provider to authenticate with (e.g., GoogleOAuth, MicrosoftOAuth, GitHubOAuth).
* @param string|null $prompt Controls the authentication flow behavior for the user.
* @param string|null $state An opaque value used to maintain state between the request and the callback.
* @param string|null $organizationId The ID of the organization to authenticate the user against.
* @param string $redirectUri The callback URI where the authorization code will be sent after authentication.
* @return string
*/
public function getAuthorizationUrl(
string $redirectUri,
?string $codeChallengeMethod = null,
?string $codeChallenge = null,
?string $domainHint = null,
?string $connectionId = null,
?array $providerQueryParams = null,
?array $providerScopes = null,
?string $invitationToken = null,
?\WorkOS\Resource\UserManagementAuthenticationScreenHint $screenHint = null,
?string $loginHint = null,
?\WorkOS\Resource\UserManagementAuthenticationProvider $provider = null,
?string $prompt = null,
?string $state = null,
?string $organizationId = null,
?\WorkOS\RequestOptions $options = null,
): string {
$query = array_filter([
'code_challenge_method' => $codeChallengeMethod,
'code_challenge' => $codeChallenge,
'domain_hint' => $domainHint,
'connection_id' => $connectionId,
'provider_query_params' => $providerQueryParams,
'provider_scopes' => $providerScopes,
'invitation_token' => $invitationToken,
'screen_hint' => $screenHint?->value,
'login_hint' => $loginHint,
'provider' => $provider?->value,
'prompt' => $prompt,
'state' => $state,
'organization_id' => $organizationId,
'redirect_uri' => $redirectUri,
'response_type' => 'code',
], fn ($v) => $v !== null);
$query['client_id'] = $this->client->requireClientId();
return $this->client->buildUrl('user_management/authorize', $query, $options);
}
/**
* Get device authorization URL
*
* Initiates the CLI Auth flow by requesting a device code and verification URLs. This endpoint implements the OAuth 2.0 Device Authorization Flow ([RFC 8628](https://datatracker.ietf.org/doc/html/rfc8628)) and is designed for command-line applications or other devices with limited input capabilities.
* @param string $clientId The WorkOS client ID for your application.
* @return \WorkOS\Resource\DeviceAuthorizationResponse
*/
public function createDevice(
string $clientId,
?\WorkOS\RequestOptions $options = null,
): \WorkOS\Resource\DeviceAuthorizationResponse {
$body = [
'client_id' => $clientId,
];
$response = $this->client->request(
method: 'POST',
path: 'user_management/authorize/device',
body: $body,
options: $options,
);
return DeviceAuthorizationResponse::fromArray($response);
}
/**
* Logout
*
* Logout a user from the current [session](https://workos.com/docs/reference/authkit/session).
* @param string $sessionId The ID of the session to revoke. This can be extracted from the `sid` claim of the access token.
* @param string|null $returnTo The URL to redirect the user to after session revocation.
* @return string
*/
public function getLogoutUrl(
string $sessionId,
?string $returnTo = null,
?\WorkOS\RequestOptions $options = null,
): string {
$query = array_filter([
'session_id' => $sessionId,
'return_to' => $returnTo,
], fn ($v) => $v !== null);
return $this->client->buildUrl('user_management/sessions/logout', $query, $options);
}
/**
* Revoke Session
*
* Revoke a [user session](https://workos.com/docs/reference/authkit/session).
* @param string $sessionId The ID of the session to revoke. This can be extracted from the `sid` claim of the access token.
* @param string|null $returnTo The URL to redirect the user to after session revocation.
* @return mixed
*/
public function revokeSession(
string $sessionId,
?string $returnTo = null,
?\WorkOS\RequestOptions $options = null,
): mixed {
$body = array_filter([
'session_id' => $sessionId,
'return_to' => $returnTo,
], fn ($v) => $v !== null);
$response = $this->client->request(
method: 'POST',
path: 'user_management/sessions/revoke',
body: $body,
options: $options,
);
return $response;
}
/**
* Create a CORS origin
*
* Creates a new CORS origin for the current environment. CORS origins allow browser-based applications to make requests to the WorkOS API.
* @param string $origin The origin URL to allow for CORS requests.
* @return \WorkOS\Resource\CORSOriginResponse
*/
public function createCorsOrigin(
string $origin,
?\WorkOS\RequestOptions $options = null,
): \WorkOS\Resource\CORSOriginResponse {
$body = [
'origin' => $origin,
];
$response = $this->client->request(
method: 'POST',
path: 'user_management/cors_origins',
body: $body,
options: $options,
);
return CORSOriginResponse::fromArray($response);
}
/**
* Get an email verification code
*
* Get the details of an existing email verification code that can be used to send an email to a user for verification.
* @param string $id The ID of the email verification code.
* @return \WorkOS\Resource\EmailVerification
*/
public function getEmailVerification(
string $id,
?\WorkOS\RequestOptions $options = null,
): \WorkOS\Resource\EmailVerification {
$response = $this->client->request(
method: 'GET',
path: "user_management/email_verification/{$id}",
options: $options,
);
return EmailVerification::fromArray($response);
}
/**
* Create a password reset token
*
* Creates a one-time token that can be used to reset a user's password.
* @param string $email The email address of the user requesting a password reset.
* @return \WorkOS\Resource\PasswordReset
*/
public function resetPassword(
string $email,
?\WorkOS\RequestOptions $options = null,
): \WorkOS\Resource\PasswordReset {
$body = [
'email' => $email,
];
$response = $this->client->request(
method: 'POST',
path: 'user_management/password_reset',
body: $body,
options: $options,
);
return PasswordReset::fromArray($response);
}
/**
* Reset the password
*
* Sets a new password using the `token` query parameter from the link that the user received. Successfully resetting the password will verify a user's email, if it hasn't been verified yet.
* @param string $token The password reset token.
* @param string $newPassword The new password to set for the user.
* @return \WorkOS\Resource\ResetPasswordResponse
*/
public function confirmPasswordReset(
string $token,
string $newPassword,
?\WorkOS\RequestOptions $options = null,
): \WorkOS\Resource\ResetPasswordResponse {
$body = [
'token' => $token,
'new_password' => $newPassword,
];
$response = $this->client->request(
method: 'POST',
path: 'user_management/password_reset/confirm',
body: $body,
options: $options,
);
return ResetPasswordResponse::fromArray($response);
}
/**
* Get a password reset token
*
* Get the details of an existing password reset token that can be used to reset a user's password.
* @param string $id The ID of the password reset token.
* @return \WorkOS\Resource\PasswordReset
*/
public function getPasswordReset(
string $id,
?\WorkOS\RequestOptions $options = null,
): \WorkOS\Resource\PasswordReset {
$response = $this->client->request(
method: 'GET',
path: "user_management/password_reset/{$id}",
options: $options,
);
return PasswordReset::fromArray($response);
}
/**
* List users
*
* Get a list of all of your existing users matching the criteria specified.
* @param string|null $before An object ID that defines your place in the list. When the ID is not present, you are at the end of the list. For example, if you make a list request and receive 100 objects, ending with `"obj_123"`, your subsequent call can include `before="obj_123"` to fetch a new batch of objects before `"obj_123"`.
* @param string|null $after An object ID that defines your place in the list. When the ID is not present, you are at the end of the list. For example, if you make a list request and receive 100 objects, ending with `"obj_123"`, your subsequent call can include `after="obj_123"` to fetch a new batch of objects after `"obj_123"`.
* @param int|null $limit Upper limit on the number of objects to return, between `1` and `100`. Defaults to 10.
* @param \WorkOS\Resource\EventsOrder|null $order Order the results by the creation time. Supported values are `"asc"` (ascending), `"desc"` (descending), and `"normal"` (descending with reversed cursor semantics where `before` fetches older records and `after` fetches newer records). Defaults to descending. Defaults to "desc".
* @param string|null $organization (deprecated) Filter users by the organization they are a member of. Deprecated in favor of `organization_id`.
* @param string|null $organizationId Filter users by the organization they are a member of.
* @param string|null $email Filter users by their email address.
* @return \WorkOS\PaginatedResponse<\WorkOS\Resource\User>
*/
public function listUsers(
?string $before = null,
?string $after = null,
?int $limit = null,
?\WorkOS\Resource\EventsOrder $order = null,
?string $organization = null,
?string $organizationId = null,
?string $email = null,
?\WorkOS\RequestOptions $options = null,
): \WorkOS\PaginatedResponse {
$query = array_filter([
'before' => $before,
'after' => $after,
'limit' => $limit,
'order' => $order?->value,
'organization' => $organization,
'organization_id' => $organizationId,
'email' => $email,
], fn ($v) => $v !== null);
return $this->client->requestPage(
method: 'GET',
path: 'user_management/users',
query: $query,
modelClass: User::class,
options: $options,
);
}
/**
* Create a user
*
* Create a new user in the current environment.
* @param string $email The email address of the user.
* @param string|null $password The password to set for the user. Mutually exclusive with `password_hash` and `password_hash_type`.
* @param string|null $passwordHash The hashed password to set for the user. Mutually exclusive with `password`.
* @param \WorkOS\Resource\CreateUserPasswordHashType|null $passwordHashType The algorithm originally used to hash the password, used when providing a `password_hash`.
* @param string|null $firstName The first name of the user.
* @param string|null $lastName The last name of the user.
* @param bool|null $emailVerified Whether the user's email has been verified.
* @param array<string, string>|null $metadata Object containing metadata key/value pairs associated with the user.
* @param string|null $externalId The external ID of the user.
* @return \WorkOS\Resource\User
*/
public function createUser(
string $email,
?string $password = null,
?string $passwordHash = null,
?\WorkOS\Resource\CreateUserPasswordHashType $passwordHashType = null,
?string $firstName = null,
?string $lastName = null,
?bool $emailVerified = null,
?array $metadata = null,
?string $externalId = null,
?\WorkOS\RequestOptions $options = null,
): \WorkOS\Resource\User {
$body = array_filter([
'email' => $email,
'password' => $password,
'password_hash' => $passwordHash,
'password_hash_type' => $passwordHashType?->value,
'first_name' => $firstName,
'last_name' => $lastName,
'email_verified' => $emailVerified,
'metadata' => $metadata,
'external_id' => $externalId,
], fn ($v) => $v !== null);
$response = $this->client->request(
method: 'POST',
path: 'user_management/users',
body: $body,
options: $options,
);
return User::fromArray($response);
}
/**
* Get a user by external ID
*
* Get the details of an existing user by an [external identifier](https://workos.com/docs/authkit/metadata/external-identifiers).
* @param string $externalId The external ID of the user.
* @return \WorkOS\Resource\User
*/
public function getUserByExternalId(
string $externalId,
?\WorkOS\RequestOptions $options = null,
): \WorkOS\Resource\User {
$response = $this->client->request(
method: 'GET',
path: "user_management/users/external_id/{$externalId}",
options: $options,
);
return User::fromArray($response);
}
/**
* Get a user
*
* Get the details of an existing user.
* @param string $id The unique ID of the user.
* @return \WorkOS\Resource\User
*/
public function getUser(
string $id,
?\WorkOS\RequestOptions $options = null,
): \WorkOS\Resource\User {
$response = $this->client->request(
method: 'GET',
path: "user_management/users/{$id}",
options: $options,
);
return User::fromArray($response);
}
/**
* Update a user
*
* Updates properties of a user. The omitted properties will be left unchanged.
* @param string $id The unique ID of the user.
* @param string|null $email The email address of the user.
* @param string|null $firstName The first name of the user.
* @param string|null $lastName The last name of the user.
* @param bool|null $emailVerified Whether the user's email has been verified.
* @param string|null $password The password to set for the user.
* @param string|null $passwordHash The hashed password to set for the user. Mutually exclusive with `password`.
* @param \WorkOS\Resource\CreateUserPasswordHashType|null $passwordHashType The algorithm originally used to hash the password, used when providing a `password_hash`.
* @param array<string, string>|null $metadata Object containing metadata key/value pairs associated with the user.
* @param string|null $externalId The external ID of the user.
* @param string|null $locale The user's preferred locale.
* @return \WorkOS\Resource\User
*/
public function updateUser(
string $id,
?string $email = null,
?string $firstName = null,
?string $lastName = null,
?bool $emailVerified = null,
?string $password = null,
?string $passwordHash = null,
?\WorkOS\Resource\CreateUserPasswordHashType $passwordHashType = null,
?array $metadata = null,
?string $externalId = null,
?string $locale = null,
?\WorkOS\RequestOptions $options = null,
): \WorkOS\Resource\User {
$body = array_filter([
'email' => $email,
'first_name' => $firstName,
'last_name' => $lastName,
'email_verified' => $emailVerified,
'password' => $password,
'password_hash' => $passwordHash,
'password_hash_type' => $passwordHashType?->value,
'metadata' => $metadata,
'external_id' => $externalId,
'locale' => $locale,
], fn ($v) => $v !== null);
$response = $this->client->request(
method: 'PUT',
path: "user_management/users/{$id}",
body: $body,
options: $options,
);
return User::fromArray($response);
}
/**
* Delete a user
*
* Permanently deletes a user in the current environment. It cannot be undone.
* @param string $id The unique ID of the user.
* @return void
*/
public function deleteUser(
string $id,
?\WorkOS\RequestOptions $options = null,
): void {
$this->client->request(
method: 'DELETE',
path: "user_management/users/{$id}",
options: $options,
);
}
/**
* Confirm email change
*
* Confirms an email change using the one-time code received by the user.
* @param string $id The unique ID of the user.
* @param string $code The one-time code used to confirm the email change.
* @return \WorkOS\Resource\EmailChangeConfirmation
*/
public function confirmEmailChange(
string $id,
string $code,
?\WorkOS\RequestOptions $options = null,
): \WorkOS\Resource\EmailChangeConfirmation {
$body = [
'code' => $code,
];
$response = $this->client->request(
method: 'POST',
path: "user_management/users/{$id}/email_change/confirm",
body: $body,
options: $options,
);
return EmailChangeConfirmation::fromArray($response);
}
/**
* Send email change code
*
* Sends an email that contains a one-time code used to change a user's email address.
* @param string $id The unique ID of the user.
* @param string $newEmail The new email address to change to.
* @return \WorkOS\Resource\EmailChange
*/
public function sendEmailChange(
string $id,
string $newEmail,
?\WorkOS\RequestOptions $options = null,
): \WorkOS\Resource\EmailChange {
$body = [
'new_email' => $newEmail,
];
$response = $this->client->request(
method: 'POST',
path: "user_management/users/{$id}/email_change/send",
body: $body,
options: $options,
);
return EmailChange::fromArray($response);
}
/**
* Verify email
*
* Verifies an email address using the one-time code received by the user.
* @param string $id The ID of the user.
* @param string $code The one-time email verification code.
* @return \WorkOS\Resource\VerifyEmailResponse
*/
public function verifyEmail(
string $id,
string $code,
?\WorkOS\RequestOptions $options = null,
): \WorkOS\Resource\VerifyEmailResponse {
$body = [
'code' => $code,
];
$response = $this->client->request(
method: 'POST',
path: "user_management/users/{$id}/email_verification/confirm",
body: $body,
options: $options,
);
return VerifyEmailResponse::fromArray($response);
}
/**
* Send verification email
*
* Sends an email that contains a one-time code used to verify a user’s email address.
* @param string $id The ID of the user.
* @return \WorkOS\Resource\SendVerificationEmailResponse
*/
public function sendVerificationEmail(
string $id,
?\WorkOS\RequestOptions $options = null,
): \WorkOS\Resource\SendVerificationEmailResponse {
$response = $this->client->request(
method: 'POST',
path: "user_management/users/{$id}/email_verification/send",
options: $options,
);
return SendVerificationEmailResponse::fromArray($response);
}
/**
* Get user identities
*
* Get a list of identities associated with the user. A user can have multiple associated identities after going through [identity linking](https://workos.com/docs/authkit/identity-linking). Currently only OAuth identities are supported. More provider types may be added in the future.
* @param string $id The unique ID of the user.
* @return array
*/
public function getUserIdentities(
string $id,
?\WorkOS\RequestOptions $options = null,
): array {
$response = $this->client->request(
method: 'GET',
path: "user_management/users/{$id}/identities",
options: $options,
);
return array_map(fn ($item) => UserIdentitiesGetItem::fromArray($item), $response);
}
/**
* List sessions
*
* Get a list of all active sessions for a specific user.
* @param string $id The ID of the user.
* @param string|null $before An object ID that defines your place in the list. When the ID is not present, you are at the end of the list. For example, if you make a list request and receive 100 objects, ending with `"obj_123"`, your subsequent call can include `before="obj_123"` to fetch a new batch of objects before `"obj_123"`.
* @param string|null $after An object ID that defines your place in the list. When the ID is not present, you are at the end of the list. For example, if you make a list request and receive 100 objects, ending with `"obj_123"`, your subsequent call can include `after="obj_123"` to fetch a new batch of objects after `"obj_123"`.
* @param int|null $limit Upper limit on the number of objects to return, between `1` and `100`. Defaults to 10.
* @param \WorkOS\Resource\EventsOrder|null $order Order the results by the creation time. Supported values are `"asc"` (ascending), `"desc"` (descending), and `"normal"` (descending with reversed cursor semantics where `before` fetches older records and `after` fetches newer records). Defaults to descending. Defaults to "desc".
* @return \WorkOS\PaginatedResponse<\WorkOS\Resource\UserSessionsListItem>
*/
public function listSessions(
string $id,
?string $before = null,
?string $after = null,
?int $limit = null,
?\WorkOS\Resource\EventsOrder $order = null,
?\WorkOS\RequestOptions $options = null,
): \WorkOS\PaginatedResponse {
$query = array_filter([
'before' => $before,
'after' => $after,
'limit' => $limit,
'order' => $order?->value,
], fn ($v) => $v !== null);
return $this->client->requestPage(
method: 'GET',
path: "user_management/users/{$id}/sessions",
query: $query,
modelClass: UserSessionsListItem::class,
options: $options,
);
}
/**
* List invitations
*
* Get a list of all of invitations matching the criteria specified.
* @param string|null $before An object ID that defines your place in the list. When the ID is not present, you are at the end of the list. For example, if you make a list request and receive 100 objects, ending with `"obj_123"`, your subsequent call can include `before="obj_123"` to fetch a new batch of objects before `"obj_123"`.
* @param string|null $after An object ID that defines your place in the list. When the ID is not present, you are at the end of the list. For example, if you make a list request and receive 100 objects, ending with `"obj_123"`, your subsequent call can include `after="obj_123"` to fetch a new batch of objects after `"obj_123"`.
* @param int|null $limit Upper limit on the number of objects to return, between `1` and `100`. Defaults to 10.
* @param \WorkOS\Resource\EventsOrder|null $order Order the results by the creation time. Supported values are `"asc"` (ascending), `"desc"` (descending), and `"normal"` (descending with reversed cursor semantics where `before` fetches older records and `after` fetches newer records). Defaults to descending. Defaults to "desc".
* @param string|null $organizationId The ID of the [organization](https://workos.com/docs/reference/organization) that the recipient will join.
* @param string|null $email The email address of the recipient.
* @return \WorkOS\PaginatedResponse<\WorkOS\Resource\UserInvite>
*/
public function listInvitations(
?string $before = null,
?string $after = null,
?int $limit = null,
?\WorkOS\Resource\EventsOrder $order = null,
?string $organizationId = null,
?string $email = null,
?\WorkOS\RequestOptions $options = null,
): \WorkOS\PaginatedResponse {
$query = array_filter([
'before' => $before,
'after' => $after,
'limit' => $limit,
'order' => $order?->value,
'organization_id' => $organizationId,
'email' => $email,
], fn ($v) => $v !== null);
return $this->client->requestPage(
method: 'GET',
path: 'user_management/invitations',
query: $query,
modelClass: UserInvite::class,
options: $options,
);
}
/**
* Send an invitation
*
* Sends an invitation email to the recipient.
* @param string $email The email address of the recipient.
* @param string|null $organizationId The ID of the [organization](https://workos.com/docs/reference/organization) that the recipient will join.
* @param string|null $roleSlug The [role](https://workos.com/docs/authkit/roles) that the recipient will receive when they join the organization in the invitation.
* @param int|null $expiresInDays How many days the invitations will be valid for. Must be between 1 and 30 days. Defaults to 7 days if not specified.
* @param string|null $inviterUserId The ID of the [user](https://workos.com/docs/reference/authkit/user) who invites the recipient. The invitation email will mention the name of this user.
* @param \WorkOS\Resource\CreateUserInviteOptionsLocale|null $locale The locale to use when rendering the invitation email. See [supported locales](https://workos.com/docs/authkit/hosted-ui/localization).
* @return \WorkOS\Resource\UserInvite
*/
public function sendInvitation(
string $email,
?string $organizationId = null,
?string $roleSlug = null,
?int $expiresInDays = null,
?string $inviterUserId = null,
?\WorkOS\Resource\CreateUserInviteOptionsLocale $locale = null,
?\WorkOS\RequestOptions $options = null,
): \WorkOS\Resource\UserInvite {
$body = array_filter([
'email' => $email,
'organization_id' => $organizationId,
'role_slug' => $roleSlug,
'expires_in_days' => $expiresInDays,
'inviter_user_id' => $inviterUserId,
'locale' => $locale?->value,
], fn ($v) => $v !== null);
$response = $this->client->request(
method: 'POST',
path: 'user_management/invitations',
body: $body,
options: $options,
);