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
13class Create
14{
15 private array $settings;
16 private string $sessionId;
17 private string $sessionToken;
18 private string $smsCode;
19 private string $emailCode;
20 private array $request;
21
25 public function __construct(array $settings) {
26 $this->settings = $settings;
27 }
28
33 public function setUserId(string $userid) {
34 $this->request["checks"]["user"]["userId"] = $userid;
35 }
36
41 public function setLoginName(string $loginName) {
42 $this->request["checks"]["user"]["loginName"] = $loginName;
43 }
44
49 public function setPassword(string $password) {
50 $this->request["checks"]["password"]["password"] = $password;
51 }
52
58 public function setIdpIntentId(string $idpIntentId) {
59 $this->request["checks"]["idpIntent"]["idpIntentId"] = $idpIntentId;
60 }
61
67 public function setIdpIntentToken(string $idpIntentToken) {
68 $this->request["checks"]["idpIntent"]["idpIntentToken"] = $idpIntentToken;
69 }
70
75 public function setTOTPCode(string $totpCode) {
76 $this->request["checks"]["totp"]["code"] = $totpCode;
77 }
78
83 public function setSmsCode(string $smsCode) {
84 $this->request["checks"]["otpSms"]["code"] = $smsCode;
85 }
86
91 public function setOtpEmail(string $otpEmail) {
92 $this->request["checks"]["otpEmail"]["code"] = $otpEmail;
93 }
94
98 public function returnSmsCode() {
99 $this->request["challenges"]["otpSms"]["returnCode"] = true;
100 }
101
105 public function returnEmailCode() {
106 $this->request["challenges"]["otpEmail"]["returnCode"] = json_decode("{}");
107 }
108
113 public function setLifetime(int $seconds) {
114 $this->request["lifetime"] = $seconds . "s";
115 }
116
120 public function getSessionId(): string {
121 return $this->sessionId;
122 }
123
127 public function getSessionToken(): string {
128 return $this->sessionToken;
129 }
130
134 public function getSmsCode(): string {
135 return $this->smsCode;
136 }
137
141 public function getEmailCode(): string {
142 return $this->emailCode;
143 }
144
149 public function create() {
150 $token = $this->settings["serviceUserToken"];
151 $curl = curl_init();
152 curl_setopt_array($curl, array(
153 CURLOPT_URL => $this->settings["domain"] . "/v2beta/sessions",
154 CURLOPT_RETURNTRANSFER => true,
155 CURLOPT_ENCODING => '',
156 CURLOPT_MAXREDIRS => 10,
157 CURLOPT_TIMEOUT => 0,
158 CURLOPT_FOLLOWLOCATION => true,
159 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
160 CURLOPT_CUSTOMREQUEST => 'POST',
161 CURLOPT_POSTFIELDS => json_encode($this->request),
162 CURLOPT_HTTPHEADER => array(
163 "Content-Type: application/json",
164 "Accept: application/json",
165 "Authorization: Bearer $token"
166 ),
167 ));
168
169 $response = json_decode(curl_exec($curl));
170 if(isset($response->code)) {
171 throw new Exception("Error-Code: " . $response->code . " Message: " . $response->message);
172 } else {
173 $this->sessionId = $response->sessionId;
174 $this->sessionToken = $response->sessionToken;
175 if (isset($response->challenges->otpSms)) {
176 $this->smsCode = $response->challenges->otpSms;
177 }
178
179 if (isset($response->challenges->otpEmail)) {
180 $this->emailCode = $response->challenges->otpEmail;
181 }
182 }
183 curl_close($curl);
184 }
185
186}
setSmsCode(string $smsCode)
Definition Create.php:83
setPassword(string $password)
Definition Create.php:49
setOtpEmail(string $otpEmail)
Definition Create.php:91
setIdpIntentId(string $idpIntentId)
Definition Create.php:58
setUserId(string $userid)
Definition Create.php:33
__construct(array $settings)
Definition Create.php:25
setLoginName(string $loginName)
Definition Create.php:41
setIdpIntentToken(string $idpIntentToken)
Definition Create.php:67
setTOTPCode(string $totpCode)
Definition Create.php:75