ldc-crm/app/Http/Middleware/MailjetChecker.php
2021-11-05 16:26:59 +01:00

32 lines
923 B
PHP

<?php
namespace App\Http\Middleware;
use Closure;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
class MailjetChecker
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @param string[] ...$guards
* @return mixed
*
* @throws \Illuminate\Auth\AuthenticationException
*/
public function handle($request, Closure $next)
{
$auth = $request->header('Authorization');
$authDecode = base64_decode(\str_replace('Basic ', '', $auth));
$authCreds = \explode(':', $authDecode);
$check = ($authCreds[0] ?? '') === config('mailjet.login');
$check = $check && (($authCreds[1] ?? '') === config('mailjet.password'));
if (!$check) {
throw new BadRequestHttpException();
}
return $next($request);
}
}