Skip to content

Commit 8f4f9f4

Browse files
simonsolutionssibprogrammer
authored andcommitted
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/
1 parent 87980e9 commit 8f4f9f4

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/Api/Operator/Session.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,29 @@
77

88
class Session extends \PleskX\Api\Operator
99
{
10+
/**
11+
* @param string $username
12+
* @param string $userIp
13+
* @param string $sourceServer
14+
*
15+
* @return string
16+
*/
17+
public function create($username, $userIp, $sourceServer = '')
18+
{
19+
$packet = $this->_client->getPacket();
20+
$creator = $packet->addChild('server')->addChild('create_session');
21+
22+
$creator->addChild('login', $username);
23+
$loginData = $creator->addChild('data');
24+
25+
$loginData->addChild('user_ip', base64_encode($userIp));
26+
$loginData->addChild('source_server', base64_encode($sourceServer));
27+
28+
$response = $this->_client->request($packet);
29+
30+
return (string) $response->id;
31+
}
32+
1033
/**
1134
* @return Struct\Info[]
1235
*/

tests/SessionTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@
55

66
class SessionTest extends TestCase
77
{
8+
9+
public function testCreate()
10+
{
11+
$sessionToken = static::$_client->session()->create('admin', '127.0.0.1', '');
12+
13+
$this->assertIsString($sessionToken);
14+
}
15+
816
public function testGet()
917
{
1018
$sessionId = static::$_client->server()->createSession('admin', '127.0.0.1');

0 commit comments

Comments
 (0)