mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-30 09:53:58 +00:00
large commit
This commit is contained in:
@@ -2,27 +2,45 @@
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Classes\Exceptions\AccessUnauthorisedException;
|
||||
use App\Classes\ValueObjects\Constants\HttpStatus;
|
||||
use App\Classes\ValueObjects\Response\ApiResponseObject;
|
||||
use Closure;
|
||||
use Exception;
|
||||
use Tymon\JWTAuth\Facades\JWTAuth;
|
||||
use Tymon\JWTAuth\JWT;
|
||||
|
||||
class ValidateToken
|
||||
{
|
||||
/** @var JWT */
|
||||
private $manager;
|
||||
|
||||
/**
|
||||
* ValidateToken constructor.
|
||||
* @param JWT $manager
|
||||
*/
|
||||
public function __construct(JWT $manager)
|
||||
{
|
||||
$this->manager = $manager;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks if jwt token is valid.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
try {
|
||||
JWTAuth::parseToken()->authenticate();
|
||||
|
||||
if(!$this->manager->check()){ throw new AccessUnauthorisedException(); }
|
||||
|
||||
} catch (Exception $exception) {
|
||||
|
||||
return (new ApiResponseObject('Authentication', 'To keep your account secure we need to re-validate your account', HttpStatus::ACCESS_UNAUTHORISED))->handler();
|
||||
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
|
||||
Reference in New Issue
Block a user