Files
Deathgarden_Rebirth-Rewrite/dist/app/Http/Middleware/VerifyLauncherPublishToken.php
Shaggy84675 1168e55140 Let the launcher CI publish releases through the API
Add POST /api/v1/launcher/releases so the launcher workflow can upload
its release zip directly instead of someone uploading it in the admin
tool. The zip goes through the same validation and publisher.

- Requires LAUNCHER_PUBLISH_TOKEN as a bearer token (401 when wrong or
  missing); publishing through the API is disabled (403) while unset
- Errors on launcher API routes are rendered as JSON, so the CI gets a
  422 with the rejection reason without sending an Accept header
- The Authorization header is no longer written to the exception log
- Document that the CI treats "already been published" as a re-run
- Rename the admin upload label to "Upload update files"
2026-11-30 23:46:28 +01:00

32 lines
956 B
PHP

<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Container\Attributes\Config;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
/**
* Lets the launcher CI publish releases: the request must carry LAUNCHER_PUBLISH_TOKEN as a bearer token.
* Publishing through the API is disabled while no token is configured.
*/
class VerifyLauncherPublishToken
{
public function __construct(
#[Config('services.launcher.publish_token')]
protected ?string $publishToken = null,
) {}
/**
* @param Closure(Request): (Response) $next
*/
public function handle(Request $request, Closure $next): Response
{
abort_if(blank($this->publishToken), 403, 'Launcher publishing through the API is disabled.');
abort_unless(hash_equals($this->publishToken, (string) $request->bearerToken()), 401, 'Invalid launcher publish token.');
return $next($request);
}
}