Updated plex manager to generate access tokens even for admin users.

This commit is contained in:
Abdulmhsen B. A. A
2023-11-20 13:11:19 +03:00
parent d7b61f6bd4
commit 4c5237c8a3
2 changed files with 28 additions and 37 deletions

23
composer.lock generated
View File

@@ -2811,12 +2811,12 @@
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/Roave/SecurityAdvisories.git", "url": "https://github.com/Roave/SecurityAdvisories.git",
"reference": "b06feb3f7e6aaacf37e47bc0bf045e3baeb06374" "reference": "ed4318ac306a1a1d467d19c1a768ff17e2d454b1"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/Roave/SecurityAdvisories/zipball/b06feb3f7e6aaacf37e47bc0bf045e3baeb06374", "url": "https://api.github.com/repos/Roave/SecurityAdvisories/zipball/ed4318ac306a1a1d467d19c1a768ff17e2d454b1",
"reference": "b06feb3f7e6aaacf37e47bc0bf045e3baeb06374", "reference": "ed4318ac306a1a1d467d19c1a768ff17e2d454b1",
"shasum": "" "shasum": ""
}, },
"conflict": { "conflict": {
@@ -2825,6 +2825,7 @@
"adodb/adodb-php": "<=5.20.20|>=5.21,<=5.21.3", "adodb/adodb-php": "<=5.20.20|>=5.21,<=5.21.3",
"aheinze/cockpit": "<2.2", "aheinze/cockpit": "<2.2",
"aimeos/aimeos-typo3": "<19.10.12|>=20,<20.10.5", "aimeos/aimeos-typo3": "<19.10.12|>=20,<20.10.5",
"airesvsg/acf-to-rest-api": "<=3.1",
"akaunting/akaunting": "<2.1.13", "akaunting/akaunting": "<2.1.13",
"akeneo/pim-community-dev": "<5.0.119|>=6,<6.0.53", "akeneo/pim-community-dev": "<5.0.119|>=6,<6.0.53",
"alextselegidis/easyappointments": "<1.5", "alextselegidis/easyappointments": "<1.5",
@@ -2896,7 +2897,7 @@
"codeigniter4/shield": "<1.0.0.0-beta4", "codeigniter4/shield": "<1.0.0.0-beta4",
"codiad/codiad": "<=2.8.4", "codiad/codiad": "<=2.8.4",
"composer/composer": "<1.10.27|>=2,<2.2.22|>=2.3,<2.6.4", "composer/composer": "<1.10.27|>=2,<2.2.22|>=2.3,<2.6.4",
"concrete5/concrete5": "<=9.2.1", "concrete5/concrete5": "<9.2.2",
"concrete5/core": "<8.5.8|>=9,<9.1", "concrete5/core": "<8.5.8|>=9,<9.1",
"contao-components/mediaelement": ">=2.14.2,<2.21.1", "contao-components/mediaelement": ">=2.14.2,<2.21.1",
"contao/contao": ">=4,<4.4.56|>=4.5,<4.9.40|>=4.10,<4.11.7|>=4.13,<4.13.21|>=5.1,<5.1.4", "contao/contao": ">=4,<4.4.56|>=4.5,<4.9.40|>=4.10,<4.11.7|>=4.13,<4.13.21|>=5.1,<5.1.4",
@@ -3504,7 +3505,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2023-11-15T19:04:11+00:00" "time": "2023-11-17T23:04:10+00:00"
}, },
{ {
"name": "sebastian/cli-parser", "name": "sebastian/cli-parser",
@@ -4556,16 +4557,16 @@
}, },
{ {
"name": "theseer/tokenizer", "name": "theseer/tokenizer",
"version": "1.2.1", "version": "1.2.2",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/theseer/tokenizer.git", "url": "https://github.com/theseer/tokenizer.git",
"reference": "34a41e998c2183e22995f158c581e7b5e755ab9e" "reference": "b2ad5003ca10d4ee50a12da31de12a5774ba6b96"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/theseer/tokenizer/zipball/34a41e998c2183e22995f158c581e7b5e755ab9e", "url": "https://api.github.com/repos/theseer/tokenizer/zipball/b2ad5003ca10d4ee50a12da31de12a5774ba6b96",
"reference": "34a41e998c2183e22995f158c581e7b5e755ab9e", "reference": "b2ad5003ca10d4ee50a12da31de12a5774ba6b96",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@@ -4594,7 +4595,7 @@
"description": "A small library for converting tokenized PHP source code into XML and potentially other formats", "description": "A small library for converting tokenized PHP source code into XML and potentially other formats",
"support": { "support": {
"issues": "https://github.com/theseer/tokenizer/issues", "issues": "https://github.com/theseer/tokenizer/issues",
"source": "https://github.com/theseer/tokenizer/tree/1.2.1" "source": "https://github.com/theseer/tokenizer/tree/1.2.2"
}, },
"funding": [ "funding": [
{ {
@@ -4602,7 +4603,7 @@
"type": "github" "type": "github"
} }
], ],
"time": "2021-07-28T10:34:58+00:00" "time": "2023-11-20T00:12:19+00:00"
} }
], ],
"aliases": [], "aliases": [],

View File

@@ -6,6 +6,7 @@ namespace App\Backends\Plex;
use App\Backends\Common\ManageInterface; use App\Backends\Common\ManageInterface;
use App\Libs\Options; use App\Libs\Options;
use Psr\Log\LoggerInterface as iLogger;
use RuntimeException; use RuntimeException;
use Symfony\Component\Console\Helper\QuestionHelper; use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Input\InputInterface as iInput; use Symfony\Component\Console\Input\InputInterface as iInput;
@@ -23,6 +24,7 @@ class PlexManage implements ManageInterface
private iHttp $http, private iHttp $http,
private iOutput $output, private iOutput $output,
private iInput $input, private iInput $input,
protected iLogger $logger
) { ) {
$this->questionHelper = new QuestionHelper(); $this->questionHelper = new QuestionHelper();
} }
@@ -342,22 +344,10 @@ class PlexManage implements ManageInterface
$user = $this->questionHelper->ask($this->input, $this->output, $question); $user = $this->questionHelper->ask($this->input, $this->output, $question);
$backend = ag_set($backend, 'user', $map[$user]); $backend = ag_set($backend, 'user', $map[$user]);
if (false === (bool)ag($userInfo[$map[$user]], 'admin')) {
$this->output->writeln( $this->output->writeln(
r( r('<info>Requesting plex token for [{user}] from plex.tv API.</info>', [
<<<HELP
The selected user [<value>{user}</value>] is not the <flag>main</flag> user of the server.
Thus syncing the user watch state using the provided token is not possible, as <value>Plex</value>
use tokens to identify users rather than user ids. We are going to attempt to generate access
token for the [<value>{user}</value>] and replace the given token with it.
------------------
<info>This might lead to some functionality to not work as expected, like listing backend users.
this is expected as the managed user token is rather limited compared to the admin user token.</info>
HELP,
[
'user' => ag($userInfo[$map[$user]], 'name') ?? 'None', 'user' => ag($userInfo[$map[$user]], 'name') ?? 'None',
] ])
)
); );
try { try {
@@ -365,14 +355,14 @@ class PlexManage implements ManageInterface
ag($userInfo[$map[$user]], 'uuid', $map[$user]), ag($userInfo[$map[$user]], 'uuid', $map[$user]),
$user $user
); );
if (null === ag($backend, 'options.' . Options::ADMIN_TOKEN)) {
$backend = ag_set($backend, 'options.' . Options::ADMIN_TOKEN, ag($backend, 'token')); $backend = ag_set($backend, 'options.' . Options::ADMIN_TOKEN, ag($backend, 'token'));
}
} catch (RuntimeException $e) { } catch (RuntimeException $e) {
$errorType = 'token'; $errorType = 'token';
throw $e; throw $e;
} }
} else {
$backend = ag_delete($backend, 'options.' . Options::ADMIN_TOKEN);
}
if (null === ($userToken = ag($userInfo[$map[$user]], 'token'))) { if (null === ($userToken = ag($userInfo[$map[$user]], 'token'))) {
$this->output->writeln( $this->output->writeln(