Zitadel PHP Client 1.3.6 PHP Client for Zitadel

Loading...
Searching...
No Matches
Terminate.php
Go to the documentation of this file.
1<?php
2
3 namespace ZitadelPhpClient\Session;
4
5use Exception;
6
10 class Terminate
11{
12 private array $settings;
13 private string $sessionId;
14 private string $sessionToken;
15
19 public function __construct(array $settings) {
20 $this->settings = $settings;
21 }
22
27 public function setSessionId(string $sessionId) {
28 $this->sessionId = $sessionId;
29 }
30
35 public function setSessionToken(string $sessionToken) {
36 $this->sessionToken = $sessionToken;
37 }
38
43 public function terminate() {
44 $token = $this->settings["serviceUserToken"];
45 $curl = curl_init();
46 curl_setopt_array($curl, array(
47 CURLOPT_URL => $this->settings["domain"] . "/v2beta/sessions/$this->sessionId",
48 CURLOPT_RETURNTRANSFER => true,
49 CURLOPT_ENCODING => '',
50 CURLOPT_MAXREDIRS => 10,
51 CURLOPT_TIMEOUT => 0,
52 CURLOPT_FOLLOWLOCATION => true,
53 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
54 CURLOPT_CUSTOMREQUEST => 'DELETE',
55 CURLOPT_POSTFIELDS => "{
56 \"sessionToken\": \"$this->sessionToken\"
57 }",
58 CURLOPT_HTTPHEADER => array(
59 "Content-Type: application/json",
60 "Accept: application/json",
61 "Authorization: Bearer $token"
62 ),
63 ));
64
65 $response = json_decode(curl_exec($curl));
66 if(isset($response->code)) {
67 throw new Exception("Error-Code: " . $response->code . " Message: " . $response->message);
68 }
69 curl_close($curl);
70 }
71}
ZitadelPhpClient\Session\Terminate
Definition Terminate.php:11
ZitadelPhpClient\Session\Terminate\setSessionToken
setSessionToken(string $sessionToken)
Definition Terminate.php:35
ZitadelPhpClient\Session\Terminate\setSessionId
setSessionId(string $sessionId)
Definition Terminate.php:27
ZitadelPhpClient\Session\Terminate\__construct
__construct(array $settings)
Definition Terminate.php:19
ZitadelPhpClient\Session\Terminate\terminate
terminate()
Definition Terminate.php:43
ZitadelPhpClient\Session
Definition Create.php:3