bearerToken() ?? $request->query('api_key'); if (empty($key)) { return response()->json([ 'error' => 'API key is verplicht. Gebruik Authorization: Bearer of ?api_key=', ], 401); } $apiKey = RadioApiKey::active()->where('key', $key)->first(); if (! $apiKey) { return response()->json([ 'error' => 'API key is ongeldig of verlopen', ], 401); } if (! $apiKey->isAllowedIp($request->ip())) { return response()->json([ 'error' => 'IP-adres niet toegestaan voor deze API key', ], 403); } if (! $apiKey->hasPermission($permission)) { return response()->json([ 'error' => 'Geen toestemming voor deze actie', ], 403); } $apiKey->touchLastUsed(); $request->merge(['radio_api_key_id' => $apiKey->id]); return $next($request); } }