12 private array $settings;
13 private array $request;
15 private string $username;
16 private string $organizationId;
17 private string $organizationDomain;
18 private string $givenName;
19 private string $familyName;
20 private string $nickName;
21 private string $displayName;
22 private string $preferredLanguage;
23 private string $gender;
24 private string $email;
25 private bool $isEmailVerified;
26 private string $phone;
27 private bool $isPhoneVerified;
28 private string $password;
29 private bool $passwordChangeRequired;
30 private array $metadata;
31 private array $idpLinks;
38 $this->settings = $settings;
47 $this->request[
"userId"] = $userid;
56 $this->request[
"username"] = $username;
66 $this->request[
"organization"][
"orgId"] = $orgId;
67 $this->request[
"organization"][
"orgDomain"] = $orgDomain;
75 public function setName(
string $givenName,
string $familyName)
77 $this->request[
"profile"][
"givenName"] = $givenName;
78 $this->request[
"profile"][
"familyName"] = $familyName;
87 $this->request[
"profile"][
"nickName"] = $nickName;
96 $this->request[
"profile"][
"displayName"] = $displayName;
104 $this->request[
"profile"][
"preferredLanguage"] = $lang;
112 if ($gender ==
"GENDER_FEMALE" or $gender ==
"GENDER_MALE" or $gender ==
"GENDER_DIVERSE") {
113 $this->request[
"profile"][
"gender"] = $gender;
115 $this->request[
"profile"][
"gender"] =
"GENDER_UNSPECIFIED";
124 $this->request[
"email"][
"email"] = $email;
125 $this->request[
"email"][
"isVerified"] =
true;
133 $this->request[
"phone"][
"phone"] = $phone;
134 $this->request[
"phone"][
"isVerified"] =
true;
144 $this->request[
"metadata"][] = [
146 "value" => base64_encode($value)
148 echo json_encode($this->request);
156 public function setPassword(
string $password,
bool $changeRequired) {
157 $this->request[
"password"][
"password"] = $password;
158 $this->request[
"password"][
"changeRequired"] = $changeRequired;
167 public function addIDPLink(
int $idpId,
string $userId,
string $userName) {
168 $this->request[
"idpLinks"][] = [
171 "userName" => $userName
181 $token = $this->settings[
"serviceUserToken"];
183 curl_setopt_array($curl, array(
184 CURLOPT_URL => $this->settings[
"domain"] .
"/v2beta/users/human",
185 CURLOPT_RETURNTRANSFER =>
true,
186 CURLOPT_ENCODING =>
"",
187 CURLOPT_MAXREDIRS => 10,
188 CURLOPT_TIMEOUT => 0,
189 CURLOPT_FOLLOWLOCATION =>
true,
190 CURLOPT_CUSTOMREQUEST =>
"POST",
191 CURLOPT_POSTFIELDS => json_encode($this->request),
192 CURLOPT_HTTPHEADER => array(
193 "Content-Type: application/json",
194 "Accept: application/json",
195 "Authorization: Bearer $token"
198 $response = json_decode(curl_exec($curl));
199 if(isset($response->code)) {
200 throw new Exception(
"Error-Code: " . $response->code .
" Message: " . $response->message);
setName(string $givenName, string $familyName)
setLanguage(string $lang)
setUserName(string $username)
setGender(string $gender)
setPassword(string $password, bool $changeRequired)
setUserId(string $userid)
__construct(array $settings)
addMetaData(string $key, string $value)
setDisplayName(string $displayName)
setOrganization(int $orgId, string $orgDomain)
addIDPLink(int $idpId, string $userId, string $userName)
setNickName(string $nickName)