ro
4113418c83
regrouped api calls for better organization and to add a bit more security. it now checks to make sure the incoming token matches the current session to authorize requests
30 lines
783 B
PHP
30 lines
783 B
PHP
<?php
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
use Closure;
|
|
use Illuminate\Http\Request;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
class ValidateAPIToken
|
|
{
|
|
/**
|
|
* Handle an incoming request.
|
|
*
|
|
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
|
|
*/
|
|
public function handle(Request $request, Closure $next): Response
|
|
{
|
|
$token = $request->header('fipamo-access-token');
|
|
if ($token == session('token')) {
|
|
return $next($request);
|
|
} else {
|
|
$response = [
|
|
'message' => "API Auth Fail",
|
|
'type' => 'postError',
|
|
];
|
|
return response()->json($response)->header('Content-Type', 'application/json');
|
|
}
|
|
}
|
|
}
|