Zitadel PHP Client 1.3.6
PHP Client for Zitadel
Loading...
Searching...
No Matches
Get.php
Go to the documentation of this file.
1<?php
2
4
5use Exception;
6
12class Get
13{
14 private array $settings;
15 private string $sessionId;
16 private string $sessionToken;
17 private string $creationDate;
18 private string $changeDate;
19 private string $userVerifiedAt;
20 private string $userId;
21 private string $userLoginName;
22 private string $userDisplayName;
23 private string $userOrganizationId;
24 private string $passwordVerifiedAt;
25 private string $idpVerifiedAt;
26 private string $totpVerifiedAt;
27 private string $optSmsVerifiedAt;
28 private string $otpEmailVerifiedAt;
29 private string $expirationDate;
30
31
35 public function __construct(array $settings) {
36 $this->settings = $settings;
37 }
38
43 public function setSessionId(string $sessionId) {
44 $this->sessionId = $sessionId;
45 }
46
51 public function setSessionToken(string $sessionToken) {
52 $this->sessionToken = $sessionToken;
53 }
54
58 public function getCreationDate(): string {
59 return $this->creationDate;
60 }
61
65 public function getChangeDate(): string {
66 return $this->changeDate;
67 }
68
72 public function getUserVerifiedAt(): string {
73 return $this->userVerifiedAt;
74 }
75
79 public function getUserId(): string {
80 return $this->userId;
81 }
82
86 public function getUserLoginName(): string {
87 return $this->userLoginName;
88 }
89
93 public function getUserDisplayName(): string {
94 return $this->userDisplayName;
95 }
96
100 public function getUserOrganizationId(): string {
101 return $this->userOrganizationId;
102 }
103
107 public function getPasswordVerifiedAt(): string {
108 return $this->passwordVerifiedAt;
109 }
110
114 public function getIdpVerifiedAt(): string {
115 return $this->idpVerifiedAt;
116 }
117
121 public function getEmailVerifiedAt(): string {
122 return $this->otpEmailVerifiedAt;
123 }
124
128 public function getExpirationDate(): string {
129 return $this->expirationDate;
130 }
131
135 public function getTotpVerifiedAt(): string {
136 return $this->totpVerifiedAt;
137 }
138
142 public function getSmsVerifiedAt(): string {
143 return $this->optSmsVerifiedAt;
144 }
145
150 public function get() {
151 $token = $this->settings["serviceUserToken"];
152 $curl = curl_init();
153 curl_setopt_array($curl, array(
154 CURLOPT_URL => $this->settings["domain"] . "/v2beta/sessions/$this->sessionId?sessionToken=$this->sessionToken",
155 CURLOPT_RETURNTRANSFER => true,
156 CURLOPT_ENCODING => '',
157 CURLOPT_MAXREDIRS => 10,
158 CURLOPT_TIMEOUT => 0,
159 CURLOPT_FOLLOWLOCATION => true,
160 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
161 CURLOPT_CUSTOMREQUEST => 'GET',
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->creationDate = $response->session->creationDate;
174 $this->changeDate = $response->session->changeDate;
175 $this->userVerifiedAt = $response->session->factors->user->verifiedAt;
176 $this->userId = $response->session->factors->user->id;
177 $this->userLoginName = $response->session->factors->user->loginName;
178 $this->userDisplayName = $response->session->factors->user->displayName;
179 $this->userOrganizationId = $response->session->factors->user->organizationId;
180
181 if (isset($response->session->factors->password->verifiedAt)) {
182 $this->passwordVerifiedAt = $response->session->factors->password->verifiedAt;
183 }
184
185 if (isset($response->session->factors->intent->verifiedAt)) {
186 $this->idpVerifiedAt = $response->session->factors->intent->verifiedAt;
187 }
188
189 if (isset($response->session->factors->otpEmail->verifiedAt)) {
190 $this->otpEmailVerifiedAt = $response->session->factors->otpEmail->verifiedAt;
191 }
192
193 if (isset($response->session->factors->otpSms->verifiedAt)) {
194 $this->optSmsVerifiedAt = $response->session->factors->otpSms->verifiedAt;
195 }
196
197 if (isset($response->session->factors->totp->verifiedAt)) {
198 $this->totpVerifiedAt = $response->session->factors->totp->verifiedAt;
199 }
200
201 if (isset($response->session->expirationDate)) {
202 $this->expirationDate = $response->session->expirationDate;
203 }
204 }
205 curl_close($curl);
206 }
207}
setSessionToken(string $sessionToken)
Definition Get.php:51
setSessionId(string $sessionId)
Definition Get.php:43
__construct(array $settings)
Definition Get.php:35