Skip to content

Commit ef0e75b

Browse files
committed
Added temp workaround for adding plex users with PIN. Closes #566
1 parent a95a650 commit ef0e75b

File tree

5 files changed

+32
-13
lines changed

5 files changed

+32
-13
lines changed

frontend/components/BackendAdd.vue

+18-11
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,17 @@
107107
</div>
108108
</div>
109109
</div>
110+
111+
<template v-if="'plex' === backend.type">
112+
<label class="label">User PIN</label>
113+
<div class="control has-icons-left">
114+
<input class="input" type="text" v-model="backend.options.PLEX_USER_PIN" :disabled="stage > 1">
115+
<div class="icon is-left"><i class="fas fa-key"></i></div>
116+
<p class="help">
117+
If the user you going to select is using <code>PIN</code> to login, enter the PIN here.
118+
</p>
119+
</div>
120+
</template>
110121
</template>
111122

112123
<template v-if="stage>=1">
@@ -175,16 +186,6 @@
175186
<NuxtLink @click="getUsers" v-text="'Retrieve User ids from backend.'" v-if="stage < 4"/>
176187
</p>
177188
</div>
178-
<template v-if="'plex' === backend.type">
179-
<label class="label">User PIN</label>
180-
<div class="control has-icons-left">
181-
<input class="input" type="text" v-model="backend.options.PLEX_USER_PIN" :disabled="stage > 3">
182-
<div class="icon is-left"><i class="fas fa-key"></i></div>
183-
<p class="help">
184-
If the selected user is using <code>PIN</code> to login, enter the PIN here.
185-
</p>
186-
</div>
187-
</template>
188189
</div>
189190

190191
<template v-if="stage >= 4">
@@ -488,6 +489,12 @@ const getUsers = async (showAlert = true) => {
488489
}
489490
}
490491
492+
if (backend.value.options && backend.value.options.PLEX_USER_PIN) {
493+
data.options = {
494+
PLEX_USER_PIN: backend.value.options.PLEX_USER_PIN
495+
}
496+
}
497+
491498
const response = await request(`/backends/users/${backend.value.type}?tokens=1`, {
492499
method: 'POST',
493500
body: JSON.stringify(data)
@@ -614,7 +621,7 @@ const addBackend = async () => {
614621
615622
if ('plex' === backend.value.type) {
616623
let token = users.value.find(u => u.id === backend.value.user).token
617-
if (token !== backend.value.token) {
624+
if (token && token !== backend.value.token) {
618625
backend.value.options.ADMIN_TOKEN = backend.value.token;
619626
backend.value.token = token
620627
}

src/Backends/Plex/Action/GetUserToken.php

+5-2
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,17 @@ private function getUserToken(Context $context, int|string $userId, string $user
6565
->withPort(443)->withScheme('https')->withHost('plex.tv')
6666
->withPath(r('/api/v2/home/users/{user_id}/switch', ['user_id' => $userId]));
6767

68-
$this->logger->debug('Requesting temporary access token for [{backend}] user [{username}].', [
68+
$pin = ag($context->options, Options::PLEX_USER_PIN);
69+
70+
$this->logger->debug('Requesting temporary access token for [{backend}] user [{username}]{pin}', [
6971
'backend' => $context->backendName,
7072
'username' => $username,
7173
'user_id' => $userId,
7274
'url' => (string)$url,
75+
'pin' => null !== $pin ? ' with PIN.' : '.',
7376
]);
7477

75-
if (null !== ($pin = ag($context->options, Options::PLEX_USER_PIN))) {
78+
if (null !== $pin) {
7679
$url = $url->withQuery(http_build_query(['pin' => $pin]));
7780
}
7881

src/Backends/Plex/PlexClient.php

+4
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,10 @@ public function fromRequest(array $config, iRequest $request): array
612612
$config = ag_set($config, 'options.' . Options::ADMIN_TOKEN, $val);
613613
}
614614

615+
if (null !== ($val = $params->get('options.' . Options::PLEX_USER_PIN))) {
616+
$config = ag_set($config, 'options.' . Options::PLEX_USER_PIN, $val);
617+
}
618+
615619
if (null !== ($val = $params->get('options.' . Options::PLEX_USE_OLD_PROGRESS_ENDPOINT))) {
616620
$config = ag_set($config, 'options.' . Options::PLEX_USE_OLD_PROGRESS_ENDPOINT, (bool)$val);
617621
}

src/Backends/Plex/PlexManage.php

+1
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@ public function manage(array $backend, array $opts = []): array
428428
$pin = $this->questionHelper->ask($this->input, $this->output, $question);
429429
if (!empty($pin)) {
430430
$backend = ag_set($backend, 'options.' . Options::PLEX_USER_PIN, $pin);
431+
$custom = ag_set($custom, 'options.' . Options::PLEX_USER_PIN, $pin);
431432
}
432433

433434
$this->output->writeln(

src/Libs/Traits/APITraits.php

+4
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ protected function getBasicClient(string $type, DataUtil $data): iClient
130130
$options[Options::ADMIN_TOKEN] = $data->get('options.' . Options::ADMIN_TOKEN);
131131
}
132132

133+
if (null !== $data->get('options.' . Options::PLEX_USER_PIN)) {
134+
$options[Options::PLEX_USER_PIN] = $data->get('options.' . Options::PLEX_USER_PIN);
135+
}
136+
133137
if (null !== $data->get('options.' . Options::IS_LIMITED_TOKEN)) {
134138
$options[Options::IS_LIMITED_TOKEN] = (bool)$data->get('options.' . Options::IS_LIMITED_TOKEN, false);
135139
}

0 commit comments

Comments
 (0)