mirror of
https://github.com/brian8544/turtle-wow.git
synced 2024-12-28 10:24:36 +00:00
26 lines
628 B
PHP
26 lines
628 B
PHP
<?php
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
use Closure;
|
|
use Illuminate\Http\Request;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
class ApiKeyAuthentication
|
|
{
|
|
/**
|
|
* Handle an incoming request.
|
|
*
|
|
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
|
|
*/
|
|
public function handle(Request $request, Closure $next): Response
|
|
{
|
|
$apiKey = $request->header('X-API-key');
|
|
|
|
if ($apiKey !== config('customs.external.api_key')) {
|
|
return response()->json(['error' => 'Unauthorized'], 401);
|
|
}
|
|
return $next($request);
|
|
}
|
|
}
|