Added logging to API calls

This commit is contained in:
Miguel Nogueira 2021-03-31 19:53:23 +01:00
parent f62ea9669b
commit 9baa249ba7
Signed by: miguel456
GPG Key ID: 2CF61B825316C6A0
1 changed files with 8 additions and 4 deletions

View File

@ -9,6 +9,7 @@ use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Str;
class APIAuthenticationMiddleware
@ -34,13 +35,16 @@ class APIAuthenticationMiddleware
if ($keyRecord && Hash::check($loneKey, $keyRecord->secret) && $keyRecord->status == 'active')
{
Log::alert('API Authentication Success', [
'discriminator' => $discriminator
]);
$keyRecord->last_used = Carbon::now();
$keyRecord->save();
Log::info('Recording API call, see context', [
'uri' => $request->url(),
'name' => Route::currentRouteName(),
'discriminator' => $discriminator,
'ip' => $request->ip()
]);
return $next($request);
}