mirror of
https://github.com/pterodactyl/panel.git
synced 2026-11-30 11:25:52 -05:00
Co-authored-by: Anthony <anthony@infraly.co> Co-authored-by: Sky Mulley <daniel.mulley@outlook.com>
40 lines
1.2 KiB
PHP
40 lines
1.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Pterodactyl\Http\Middleware\Api\Client;
|
|
|
|
use Closure;
|
|
use Illuminate\Http\Request;
|
|
use Laravel\Sanctum\Contracts\HasAbilities;
|
|
use Laravel\Sanctum\TransientToken;
|
|
use Pterodactyl\Http\Concerns\ResolvesRequestContext;
|
|
use Pterodactyl\Models\ApiKey;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
|
|
|
class RequireClientApiKey
|
|
{
|
|
use ResolvesRequestContext;
|
|
|
|
/**
|
|
* Blocks a request to the Client API endpoints if the user is providing an API token
|
|
* that was created for the application API.
|
|
*/
|
|
/**
|
|
* @param Closure(Request):Response $next
|
|
* @return Response
|
|
*/
|
|
public function handle(Request $request, Closure $next): mixed
|
|
{
|
|
$token = $this->authenticatedUser($request)->currentAccessToken();
|
|
if (! $token instanceof HasAbilities || $token instanceof TransientToken) {
|
|
return $next($request);
|
|
}
|
|
|
|
throw_if($token->key_type === ApiKey::TYPE_APPLICATION, AccessDeniedHttpException::class, 'You are attempting to use an application API key on an endpoint that requires a client API key.');
|
|
|
|
return $next($request);
|
|
}
|
|
}
|