Implemented subscription logic
This commit is contained in:
@ -3,9 +3,10 @@
|
||||
namespace NoccyLabs\Mercureact\Http\Middleware;
|
||||
|
||||
use NoccyLabs\Mercureact\Configuration;
|
||||
use NoccyLabs\Mercureact\Http\Exeption\SecurityException;
|
||||
use NoccyLabs\Mercureact\Http\Exception\SecurityException;
|
||||
use NoccyLabs\SimpleJWT\JWTToken;
|
||||
use NoccyLabs\SimpleJWT\Key\JWTPlaintextKey;
|
||||
use NoccyLabs\SimpleJWT\Validator\JWTValidator;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use React\Promise\Promise;
|
||||
use React\Promise\PromiseInterface;
|
||||
@ -40,7 +41,9 @@ class SecurityMiddleware
|
||||
}
|
||||
|
||||
/**
|
||||
* Check authorization and return a new request with added attributes:
|
||||
*
|
||||
* 'authorization' => JWTToken
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @return ServerRequestInterface
|
||||
@ -53,9 +56,11 @@ class SecurityMiddleware
|
||||
$key = new JWTPlaintextKey($this->config->getJwtSecret());
|
||||
$tok = new JWTToken($key, $jwt);
|
||||
if (!$tok->isValid()) {
|
||||
throw new SecurityException(message:"Invalid token", code:SecurityException::ERR_ACCESS_DENIED);
|
||||
throw new SecurityException(
|
||||
message: "Invalid token",
|
||||
code: SecurityException::ERR_ACCESS_DENIED
|
||||
);
|
||||
}
|
||||
$mercureClaims = $tok->claims->get('mercure');
|
||||
return $request
|
||||
->withAttribute('authorization', $tok);
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user