Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/app/Http/Middleware/Activity/TrackAPIKey.php
10284 views
1
<?php
2
3
namespace Pterodactyl\Http\Middleware\Activity;
4
5
use Illuminate\Http\Request;
6
use Pterodactyl\Models\ApiKey;
7
use Pterodactyl\Facades\LogTarget;
8
9
class TrackAPIKey
10
{
11
/**
12
* Determines if the authenticated user making this request is using an actual
13
* API key, or it is just a cookie authenticated session. This data is set in a
14
* request singleton so that all tracked activity log events are properly associated
15
* with the given API key.
16
*/
17
public function handle(Request $request, \Closure $next): mixed
18
{
19
if ($request->user()) {
20
$token = $request->user()->currentAccessToken();
21
22
LogTarget::setApiKeyId($token instanceof ApiKey ? $token->id : null); // @phpstan-ignore instanceof.alwaysTrue
23
}
24
25
return $next($request);
26
}
27
}
28
29