Move everything around as needed to get things setup for the client API

This commit is contained in:
Dane Everitt 2018-02-25 15:30:56 -06:00
parent 8daf97021a
commit e28973bcae
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
17 changed files with 199 additions and 46 deletions

View file

@ -6,7 +6,7 @@ use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
class AuthenticateUser
class AuthenticateApplicationUser
{
/**
* Authenticate that the currently authenticated user is an administrator

View file

@ -1,6 +1,6 @@
<?php
namespace Pterodactyl\Http\Middleware\Api\Application;
namespace Pterodactyl\Http\Middleware\Api;
use Closure;
use IPTools\IP;

View file

@ -1,6 +1,6 @@
<?php
namespace Pterodactyl\Http\Middleware\Api\Application;
namespace Pterodactyl\Http\Middleware\Api;
use Closure;
use Cake\Chronos\Chronos;
@ -50,12 +50,13 @@ class AuthenticateKey
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @param int $keyType
* @return mixed
*
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
*/
public function handle(Request $request, Closure $next)
public function handle(Request $request, Closure $next, int $keyType)
{
if (is_null($request->bearerToken())) {
throw new HttpException(401, null, null, ['WWW-Authenticate' => 'Bearer']);
@ -68,7 +69,7 @@ class AuthenticateKey
try {
$model = $this->repository->findFirstWhere([
['identifier', '=', $identifier],
['key_type', '=', ApiKey::TYPE_APPLICATION],
['key_type', '=', $keyType],
]);
} catch (RecordNotFoundException $exception) {
throw new AccessDeniedHttpException;

View file

@ -0,0 +1,27 @@
<?php
namespace Pterodactyl\Http\Middleware\Api\Client;
use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
class AuthenticateClientAccess
{
/**
* Authenticate that the currently authenticated user has permission
* to access the specified server.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle(Request $request, Closure $next)
{
if (is_null($request->user())) {
throw new AccessDeniedHttpException('This account does not have permission to access this resource.');
}
return $next($request);
}
}

View file

@ -1,6 +1,6 @@
<?php
namespace Pterodactyl\Http\Middleware\Api\Application;
namespace Pterodactyl\Http\Middleware\Api;
use Closure;
use Illuminate\Http\Request;