Zitadel PHP Client 1.3.6
PHP Client for Zitadel
Loading...
Searching...
No Matches
Create.php
Go to the documentation of this file.
1<?php
2
4
5use Exception;
6
10class Create
11{
12 private array $settings;
13 private array $request;
14 private int $userid;
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;
32
36 public function __construct(array $settings)
37 {
38 $this->settings = $settings;
39 }
40
45 public function setUserId(string $userid)
46 {
47 $this->request["userId"] = $userid;
48 }
49
54 public function setUserName(string $username)
55 {
56 $this->request["username"] = $username;
57 }
58
64 public function setOrganization(int $orgId, string $orgDomain)
65 {
66 $this->request["organization"]["orgId"] = $orgId;
67 $this->request["organization"]["orgDomain"] = $orgDomain;
68 }
69
75 public function setName(string $givenName, string $familyName)
76 {
77 $this->request["profile"]["givenName"] = $givenName;
78 $this->request["profile"]["familyName"] = $familyName;
79 }
80
85 public function setNickName(string $nickName)
86 {
87 $this->request["profile"]["nickName"] = $nickName;
88 }
89
94 public function setDisplayName(string $displayName)
95 {
96 $this->request["profile"]["displayName"] = $displayName;
97 }
98
103 public function setLanguage(string $lang) {
104 $this->request["profile"]["preferredLanguage"] = $lang;
105 }
106
111 public function setGender(string $gender) {
112 if ($gender == "GENDER_FEMALE" or $gender == "GENDER_MALE" or $gender == "GENDER_DIVERSE") {
113 $this->request["profile"]["gender"] = $gender;
114 } else {
115 $this->request["profile"]["gender"] = "GENDER_UNSPECIFIED";
116 }
117 }
118
123 public function setEmail(string $email) {
124 $this->request["email"]["email"] = $email;
125 $this->request["email"]["isVerified"] = true;
126 }
127
132 public function setPhone(string $phone) {
133 $this->request["phone"]["phone"] = $phone;
134 $this->request["phone"]["isVerified"] = true;
135
136 }
137
143 public function addMetaData(string $key, string $value) {
144 $this->request["metadata"][] = [
145 "key" => $key,
146 "value" => base64_encode($value)
147 ];
148 echo json_encode($this->request);
149 }
150
156 public function setPassword(string $password, bool $changeRequired) {
157 $this->request["password"]["password"] = $password;
158 $this->request["password"]["changeRequired"] = $changeRequired;
159 }
160
167 public function addIDPLink(int $idpId, string $userId, string $userName) {
168 $this->request["idpLinks"][] = [
169 "idpId" => $idpId,
170 "userId" => $userId,
171 "userName" => $userName
172 ];
173 }
174
179 public function create()
180 {
181 $token = $this->settings["serviceUserToken"];
182 $curl = curl_init();
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"
196 )
197 ));
198 $response = json_decode(curl_exec($curl));
199 if(isset($response->code)) {
200 throw new Exception("Error-Code: " . $response->code . " Message: " . $response->message);
201 }
202 curl_close($curl);
203 }
204}
setName(string $givenName, string $familyName)
Definition Create.php:75
setLanguage(string $lang)
Definition Create.php:103
setUserName(string $username)
Definition Create.php:54
setEmail(string $email)
Definition Create.php:123
setGender(string $gender)
Definition Create.php:111
setPhone(string $phone)
Definition Create.php:132
setPassword(string $password, bool $changeRequired)
Definition Create.php:156
setUserId(string $userid)
Definition Create.php:45
__construct(array $settings)
Definition Create.php:36
addMetaData(string $key, string $value)
Definition Create.php:143
setDisplayName(string $displayName)
Definition Create.php:94
setOrganization(int $orgId, string $orgDomain)
Definition Create.php:64
addIDPLink(int $idpId, string $userId, string $userName)
Definition Create.php:167
setNickName(string $nickName)
Definition Create.php:85