Added temp workaround for adding plex users with PIN. Closes #566

This commit is contained in:
Abdulmhsen B. A. A.
2024-11-16 11:25:31 +03:00
parent a95a65078b
commit ef0e75b17e
5 changed files with 32 additions and 13 deletions

View File

@@ -107,6 +107,17 @@
</div>
</div>
</div>
<template v-if="'plex' === backend.type">
<label class="label">User PIN</label>
<div class="control has-icons-left">
<input class="input" type="text" v-model="backend.options.PLEX_USER_PIN" :disabled="stage > 1">
<div class="icon is-left"><i class="fas fa-key"></i></div>
<p class="help">
If the user you going to select is using <code>PIN</code> to login, enter the PIN here.
</p>
</div>
</template>
</template>
<template v-if="stage>=1">
@@ -175,16 +186,6 @@
<NuxtLink @click="getUsers" v-text="'Retrieve User ids from backend.'" v-if="stage < 4"/>
</p>
</div>
<template v-if="'plex' === backend.type">
<label class="label">User PIN</label>
<div class="control has-icons-left">
<input class="input" type="text" v-model="backend.options.PLEX_USER_PIN" :disabled="stage > 3">
<div class="icon is-left"><i class="fas fa-key"></i></div>
<p class="help">
If the selected user is using <code>PIN</code> to login, enter the PIN here.
</p>
</div>
</template>
</div>
<template v-if="stage >= 4">
@@ -488,6 +489,12 @@ const getUsers = async (showAlert = true) => {
}
}
if (backend.value.options && backend.value.options.PLEX_USER_PIN) {
data.options = {
PLEX_USER_PIN: backend.value.options.PLEX_USER_PIN
}
}
const response = await request(`/backends/users/${backend.value.type}?tokens=1`, {
method: 'POST',
body: JSON.stringify(data)
@@ -614,7 +621,7 @@ const addBackend = async () => {
if ('plex' === backend.value.type) {
let token = users.value.find(u => u.id === backend.value.user).token
if (token !== backend.value.token) {
if (token && token !== backend.value.token) {
backend.value.options.ADMIN_TOKEN = backend.value.token;
backend.value.token = token
}

View File

@@ -65,14 +65,17 @@ final class GetUserToken
->withPort(443)->withScheme('https')->withHost('plex.tv')
->withPath(r('/api/v2/home/users/{user_id}/switch', ['user_id' => $userId]));
$this->logger->debug('Requesting temporary access token for [{backend}] user [{username}].', [
$pin = ag($context->options, Options::PLEX_USER_PIN);
$this->logger->debug('Requesting temporary access token for [{backend}] user [{username}]{pin}', [
'backend' => $context->backendName,
'username' => $username,
'user_id' => $userId,
'url' => (string)$url,
'pin' => null !== $pin ? ' with PIN.' : '.',
]);
if (null !== ($pin = ag($context->options, Options::PLEX_USER_PIN))) {
if (null !== $pin) {
$url = $url->withQuery(http_build_query(['pin' => $pin]));
}

View File

@@ -612,6 +612,10 @@ class PlexClient implements iClient
$config = ag_set($config, 'options.' . Options::ADMIN_TOKEN, $val);
}
if (null !== ($val = $params->get('options.' . Options::PLEX_USER_PIN))) {
$config = ag_set($config, 'options.' . Options::PLEX_USER_PIN, $val);
}
if (null !== ($val = $params->get('options.' . Options::PLEX_USE_OLD_PROGRESS_ENDPOINT))) {
$config = ag_set($config, 'options.' . Options::PLEX_USE_OLD_PROGRESS_ENDPOINT, (bool)$val);
}

View File

@@ -428,6 +428,7 @@ class PlexManage implements ManageInterface
$pin = $this->questionHelper->ask($this->input, $this->output, $question);
if (!empty($pin)) {
$backend = ag_set($backend, 'options.' . Options::PLEX_USER_PIN, $pin);
$custom = ag_set($custom, 'options.' . Options::PLEX_USER_PIN, $pin);
}
$this->output->writeln(

View File

@@ -130,6 +130,10 @@ trait APITraits
$options[Options::ADMIN_TOKEN] = $data->get('options.' . Options::ADMIN_TOKEN);
}
if (null !== $data->get('options.' . Options::PLEX_USER_PIN)) {
$options[Options::PLEX_USER_PIN] = $data->get('options.' . Options::PLEX_USER_PIN);
}
if (null !== $data->get('options.' . Options::IS_LIMITED_TOKEN)) {
$options[Options::IS_LIMITED_TOKEN] = (bool)$data->get('options.' . Options::IS_LIMITED_TOKEN, false);
}