Add support for tracking when an activity event is triggered from an API key
This commit is contained in:
parent
92c1c162af
commit
0520014c0f
7 changed files with 87 additions and 0 deletions
|
@ -16,6 +16,7 @@ use Illuminate\Routing\Middleware\ThrottleRequests;
|
|||
use Pterodactyl\Http\Middleware\LanguageMiddleware;
|
||||
use Illuminate\Foundation\Http\Kernel as HttpKernel;
|
||||
use Illuminate\Routing\Middleware\SubstituteBindings;
|
||||
use Pterodactyl\Http\Middleware\Activity\TrackAPIKey;
|
||||
use Illuminate\Session\Middleware\AuthenticateSession;
|
||||
use Illuminate\View\Middleware\ShareErrorsFromSession;
|
||||
use Pterodactyl\Http\Middleware\MaintenanceMiddleware;
|
||||
|
@ -68,6 +69,7 @@ class Kernel extends HttpKernel
|
|||
EnsureStatefulRequests::class,
|
||||
'auth:sanctum',
|
||||
IsValidJson::class,
|
||||
TrackAPIKey::class,
|
||||
RequireTwoFactorAuthentication::class,
|
||||
AuthenticateIPAccess::class,
|
||||
],
|
||||
|
|
30
app/Http/Middleware/Activity/TrackAPIKey.php
Normal file
30
app/Http/Middleware/Activity/TrackAPIKey.php
Normal file
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
namespace Pterodactyl\Http\Middleware\Activity;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Pterodactyl\Models\ApiKey;
|
||||
use Pterodactyl\Facades\LogTarget;
|
||||
|
||||
class TrackAPIKey
|
||||
{
|
||||
/**
|
||||
* Determines if the authenticated user making this request is using an actual
|
||||
* API key, or it is just a cookie authenticated session. This data is set in a
|
||||
* request singleton so that all tracked activity log events are properly associated
|
||||
* with the given API key.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle(Request $request, Closure $next)
|
||||
{
|
||||
if ($request->user()) {
|
||||
$token = $request->user()->currentAccessToken();
|
||||
|
||||
LogTarget::setApiKeyId($token instanceof ApiKey ? $token->id : null);
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue