Zitadel PHP Client 1.3.6
PHP Client for Zitadel
Loading...
Searching...
No Matches
Update.php
Go to the documentation of this file.
1<?php
2
4
5use Exception;
6
13class Update
14{
15 private array $settings;
16 private string $sessionId;
17 private string $smsCode;
18 private string $emailCode;
19 private array $request;
20
24 public function __construct(array $settings) {
25 $this->settings = $settings;
26 }
27
32 public function setSessionId(string $sessionId) {
33 $this->sessionId = $sessionId;
34 }
35
40 public function setSessionToken(string $sessionToken) {
41 $this->request["sessionToken"] = $sessionToken;
42 }
43
48 public function setPassword(string $password) {
49 $this->request["checks"]["password"]["password"] = $password;
50 }
51
57 public function setIdpIntentId(string $idpIntentId) {
58 $this->request["checks"]["idpIntent"]["idpIntentId"] = $idpIntentId;
59 }
60
66 public function setIdpIntentToken(string $idpIntentToken) {
67 $this->request["checks"]["idpIntent"]["idpIntentToken"] = $idpIntentToken;
68 }
69
74 public function setTOTPCode(string $totpCode) {
75 $this->request["checks"]["totp"]["code"] = $totpCode;
76 }
77
82 public function setSmsCode(string $smsCode) {
83 $this->request["checks"]["otpSms"]["code"] = $smsCode;
84 }
85
90 public function setOtpEmail(string $otpEmail) {
91 $this->request["checks"]["otpEmail"]["code"] = $otpEmail;
92 }
93
97 public function returnSmsCode() {
98 $this->request["challenges"]["otpSms"]["returnCode"] = true;
99 }
100
104 public function returnEmailCode() {
105 $this->request["challenges"]["otpEmail"]["returnCode"] = json_decode("{}");
106 }
107
112 public function setLifetime(int $seconds) {
113 $this->request["lifetime"] = $seconds . "s";
114 }
115
119 public function getSmsCode(): string {
120 return $this->smsCode;
121 }
122
126 public function getEmailCode(): string {
127 return $this->emailCode;
128 }
129
134 public function update() {
135 $token = $this->settings["serviceUserToken"];
136 $curl = curl_init();
137 curl_setopt_array($curl, array(
138 CURLOPT_URL => $this->settings["domain"] . "/v2beta/sessions/$this->sessionId",
139 CURLOPT_RETURNTRANSFER => true,
140 CURLOPT_ENCODING => '',
141 CURLOPT_MAXREDIRS => 10,
142 CURLOPT_TIMEOUT => 0,
143 CURLOPT_FOLLOWLOCATION => true,
144 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
145 CURLOPT_CUSTOMREQUEST => 'PATCH',
146 CURLOPT_POSTFIELDS => json_encode($this->request),
147 CURLOPT_HTTPHEADER => array(
148 "Content-Type: application/json",
149 "Accept: application/json",
150 "Authorization: Bearer $token"
151 ),
152 ));
153
154 $response = json_decode(curl_exec($curl));
155 if(isset($response->code)) {
156 throw new Exception("Error-Code: " . $response->code . " Message: " . $response->message);
157 } else {
158 if (isset($response->challenges->otpSms)) {
159 $this->smsCode = $response->challenges->otpSms;
160 }
161
162 if (isset($response->challenges->otpEmail)) {
163 $this->emailCode = $response->challenges->otpEmail;
164 }
165 }
166 curl_close($curl);
167 }
168
169}
setSessionToken(string $sessionToken)
Definition Update.php:40
setSessionId(string $sessionId)
Definition Update.php:32
setSmsCode(string $smsCode)
Definition Update.php:82
setPassword(string $password)
Definition Update.php:48
setOtpEmail(string $otpEmail)
Definition Update.php:90
setIdpIntentId(string $idpIntentId)
Definition Update.php:57
__construct(array $settings)
Definition Update.php:24
setIdpIntentToken(string $idpIntentToken)
Definition Update.php:66
setTOTPCode(string $totpCode)
Definition Update.php:74