Include PIN when validating plex context.
This commit is contained in:
@@ -9,6 +9,7 @@ use App\Backends\Plex\Action\GetUser;
|
||||
use App\Libs\Container;
|
||||
use App\Libs\Enums\Http\Status;
|
||||
use App\Libs\Exceptions\Backends\InvalidContextException;
|
||||
use App\Libs\Options;
|
||||
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
|
||||
@@ -82,6 +83,11 @@ final readonly class PlexValidateContext
|
||||
{
|
||||
try {
|
||||
$url = $context->backendUrl->withPath('/');
|
||||
|
||||
if (null !== ($pin = ag($context->options, Options::PLEX_USER_PIN))) {
|
||||
$url = $url->withQuery(http_build_query(['pin' => (string)$pin]));
|
||||
}
|
||||
|
||||
$request = $this->http->request('GET', (string)$url, [
|
||||
'headers' => [
|
||||
'Accept' => 'application/json',
|
||||
@@ -89,21 +95,25 @@ final readonly class PlexValidateContext
|
||||
],
|
||||
]);
|
||||
|
||||
if (Status::UNAUTHORIZED->value === $request->getStatusCode()) {
|
||||
if (Status::UNAUTHORIZED === Status::tryFrom($request->getStatusCode())) {
|
||||
throw new InvalidContextException('Backend responded with 401. Most likely means token is invalid.');
|
||||
}
|
||||
|
||||
if (Status::NOT_FOUND->value === $request->getStatusCode()) {
|
||||
if (Status::NOT_FOUND === Status::tryFrom($$request->getStatusCode())) {
|
||||
throw new InvalidContextException('Backend responded with 404. Most likely means url is incorrect.');
|
||||
}
|
||||
|
||||
return $request->getContent(true);
|
||||
} catch (TransportExceptionInterface $e) {
|
||||
throw new InvalidContextException(r('Failed to connect to backend. {error}', ['error' => $e->getMessage()]),
|
||||
previous: $e);
|
||||
throw new InvalidContextException(
|
||||
r('Failed to connect to backend. {error}', ['error' => $e->getMessage()]),
|
||||
previous: $e
|
||||
);
|
||||
} catch (ClientExceptionInterface $e) {
|
||||
throw new InvalidContextException(r('Got non 200 response. {error}', ['error' => $e->getMessage()]),
|
||||
previous: $e);
|
||||
throw new InvalidContextException(
|
||||
r('Got non 200 response. {error}', ['error' => $e->getMessage()]),
|
||||
previous: $e
|
||||
);
|
||||
} catch (RedirectionExceptionInterface $e) {
|
||||
throw new InvalidContextException(
|
||||
r('Redirection recursion detected. {error}', ['error' => $e->getMessage()]),
|
||||
|
||||
Reference in New Issue
Block a user