Zitadel PHP Client 1.3.6 PHP Client for Zitadel

Loading...
Searching...
No Matches
Phone.php
Go to the documentation of this file.
1<?php
2
3 namespace ZitadelPhpClient\User;
4
5use Exception;
6
10 class Phone
11{
12 private array $settings;
13 private int $userid;
14 private string $returnedVerificationCode;
18 public function __construct(array $settings) {
19 $this->settings = $settings;
20 }
21
26 public function setUserId(int $userid) {
27 $this->userid = $userid;
28 }
29
33 public function getVerificationCode(): string
34 {
35 return $this->returnedVerificationCode;
36 }
37
43 public function changePhone(string $phone) {
44 $token = $this->settings["serviceUserToken"];
45
46 $curl = curl_init();
47 curl_setopt_array($curl, array(
48 CURLOPT_URL => $this->settings["domain"] . "/v2beta/users/$this->userid/phone",
49 CURLOPT_RETURNTRANSFER => true,
50 CURLOPT_ENCODING => '',
51 CURLOPT_MAXREDIRS => 10,
52 CURLOPT_TIMEOUT => 0,
53 CURLOPT_FOLLOWLOCATION => true,
54 CURLOPT_CUSTOMREQUEST => 'POST',
55 CURLOPT_POSTFIELDS => "{
56 \"phone\": \"$phone\",
57 \"returnCode\": {}
58 }",
59 CURLOPT_HTTPHEADER => array(
60 "Content-Type: application/json",
61 "Accept: application/json",
62 "Authorization: Bearer $token"
63 ),
64 ));
65
66 $response = json_decode(curl_exec($curl));
67 curl_close($curl);
68 if(isset($response->code)) {
69 throw new Exception("Error-Code: " . $response->code . " Message: " . $response->message);
70 } else {
71 $this->returnedVerificationCode = $response->verificationCode;
72 }
73 }
74
78 public function resendVerificationCode() {
79 $curl = curl_init();
80 $token = $this->settings["serviceUserToken"];
81 curl_setopt_array($curl, array(
82 CURLOPT_URL => $this->settings["domain"] . "/v2beta/users/$this->userid/phone/resend",
83 CURLOPT_RETURNTRANSFER => true,
84 CURLOPT_ENCODING => '',
85 CURLOPT_MAXREDIRS => 10,
86 CURLOPT_TIMEOUT => 0,
87 CURLOPT_FOLLOWLOCATION => true,
88 CURLOPT_CUSTOMREQUEST => 'POST',
89 CURLOPT_POSTFIELDS =>'{
90 "returnCode": {}
91 }',
92 CURLOPT_HTTPHEADER => array(
93 "Content-Type: application/json",
94 "Accept: application/json",
95 "Authorization: Bearer $token"
96 ),
97 ));
98
99 $response = json_decode(curl_exec($curl));
100 $this->returnedVerificationCode = $response->verificationCode;
101 curl_close($curl);
102 }
103
108 public function verify(string $verifyCode): bool {
109 $token = $this->settings["serviceUserToken"];
110 $curl = curl_init();
111
112 curl_setopt_array($curl, array(
113 CURLOPT_URL => $this->settings["domain"] . "/v2beta/users/$this->userid/phone/verify",
114 CURLOPT_RETURNTRANSFER => true,
115 CURLOPT_ENCODING => '',
116 CURLOPT_MAXREDIRS => 10,
117 CURLOPT_TIMEOUT => 0,
118 CURLOPT_FOLLOWLOCATION => true,
119 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
120 CURLOPT_CUSTOMREQUEST => 'POST',
121 CURLOPT_POSTFIELDS =>"{
122 \"verificationCode\": \"$verifyCode\"
123 }",
124 CURLOPT_HTTPHEADER => array(
125 "Content-Type: application/json",
126 "Accept: application/json",
127 "Authorization: Bearer $token"
128 ),
129 ));
130
131 $response = curl_exec($curl);
132 curl_close($curl);
133 if(isset($response->code)) {
134 return false;
135 }
136 return true;
137 }
138}
ZitadelPhpClient\User\Phone
Definition Phone.php:11
ZitadelPhpClient\User\Phone\verify
verify(string $verifyCode)
Definition Phone.php:108
ZitadelPhpClient\User\Phone\setUserId
setUserId(int $userid)
Definition Phone.php:26
ZitadelPhpClient\User\Phone\getVerificationCode
getVerificationCode()
Definition Phone.php:33
ZitadelPhpClient\User\Phone\resendVerificationCode
resendVerificationCode()
Definition Phone.php:78
ZitadelPhpClient\User\Phone\__construct
__construct(array $settings)
Definition Phone.php:18
ZitadelPhpClient\User\Phone\changePhone
changePhone(string $phone)
Definition Phone.php:43
ZitadelPhpClient\User
Definition Account.php:3