From 6487567dce27471c39cda65acb7b1b09ab5fc4b9 Mon Sep 17 00:00:00 2001 From: Simon Solutions Date: Wed, 8 Sep 2021 20:32:03 +0200 Subject: [PATCH 1/2] Add create session for automatic login with token Add create session tokens for automatic login with token according to: https://docs.plesk.com/en-US/obsidian/api-rpc/about-xml-api/reference/managing-plesk-server/creating-session-tokens.73865/ --- src/Api/Operator/Session.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/Api/Operator/Session.php b/src/Api/Operator/Session.php index eb2970bd..d3df420d 100644 --- a/src/Api/Operator/Session.php +++ b/src/Api/Operator/Session.php @@ -7,6 +7,29 @@ class Session extends \PleskX\Api\Operator { + /** + * @param string $username + * @param string $userIp + * @param string $sourceServer + * + * @return string + */ + public function create($username, $userIp, $sourceServer = '') + { + $packet = $this->_client->getPacket(); + $creator = $packet->addChild('server')->addChild('create_session'); + + $creator->addChild('login', $username); + $loginData = $creator->addChild('data'); + + $loginData->addChild('user_ip', base64_encode($userIp)); + $loginData->addChild('source_server', $sourceServer); + + $response = $this->_client->request($packet); + + return (string) $response->id; + } + /** * @return Struct\Info[] */ From 55592e77992c4fdbb4c92b8ae7da23bd46cfebe4 Mon Sep 17 00:00:00 2001 From: Simon Solutions Date: Wed, 8 Sep 2021 20:46:38 +0200 Subject: [PATCH 2/2] Update Session.php --- src/Api/Operator/Session.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Api/Operator/Session.php b/src/Api/Operator/Session.php index d3df420d..af2b7c68 100644 --- a/src/Api/Operator/Session.php +++ b/src/Api/Operator/Session.php @@ -23,7 +23,7 @@ public function create($username, $userIp, $sourceServer = '') $loginData = $creator->addChild('data'); $loginData->addChild('user_ip', base64_encode($userIp)); - $loginData->addChild('source_server', $sourceServer); + $loginData->addChild('source_server', base64_encode($sourceServer)); $response = $this->_client->request($packet);