diff --git a/src/API/Backends/Add.php b/src/API/Backends/Add.php index b4098d25..9801f638 100644 --- a/src/API/Backends/Add.php +++ b/src/API/Backends/Add.php @@ -68,6 +68,10 @@ final class Add return api_error('Invalid url was given.', HTTP_STATUS::HTTP_BAD_REQUEST); } + if (null === ($token = $data->get('token'))) { + return api_error('No access token was given.', HTTP_STATUS::HTTP_BAD_REQUEST); + } + if (null === ($class = Config::get("supported.{$type}", null))) { throw api_error(r("Unexpected client type '{type}' was given.", [ 'type' => $type @@ -86,7 +90,7 @@ final class Add backendUrl: new Uri($config->get('url')), cache: Container::get(BackendCache::class), backendId: $config->get('uuid', null), - backendToken: $config->get('token'), + backendToken: $token, backendUser: $config->get('user', null), options: $config->get('options', []), ); @@ -95,6 +99,10 @@ final class Add return api_error('Context information validation failed.', HTTP_STATUS::HTTP_BAD_REQUEST); } + if (!$config->get('uuid')) { + $config = $config->with('uuid', $instance->withContext($context)->getIdentifier()); + } + if (!$config->has('webhook.token')) { $config = $config->with('webhook.token', bin2hex(random_bytes(Config::get('webhook.tokenLength')))); } diff --git a/src/Backends/Plex/PlexValidateContext.php b/src/Backends/Plex/PlexValidateContext.php index 506eb5eb..13b681d2 100644 --- a/src/Backends/Plex/PlexValidateContext.php +++ b/src/Backends/Plex/PlexValidateContext.php @@ -37,7 +37,7 @@ final readonly class PlexValidateContext throw new InvalidContextException('Failed to get backend id.'); } - if ($backendId !== $context->backendId) { + if (null !== $context->backendId && $backendId !== $context->backendId) { throw new InvalidContextException( r("Backend id mismatch. Expected '{expected}', server responded with '{actual}'.", [ 'expected' => $context->backendId,