From 9baa249ba7e807fdbe5244fbf020bf65c23144ab Mon Sep 17 00:00:00 2001 From: Miguel N Date: Wed, 31 Mar 2021 19:53:23 +0100 Subject: [PATCH] Added logging to API calls --- app/Http/Middleware/APIAuthenticationMiddleware.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/app/Http/Middleware/APIAuthenticationMiddleware.php b/app/Http/Middleware/APIAuthenticationMiddleware.php index 8797104..866fd83 100644 --- a/app/Http/Middleware/APIAuthenticationMiddleware.php +++ b/app/Http/Middleware/APIAuthenticationMiddleware.php @@ -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); }