Implemented subscription logic

This commit is contained in:
2024-03-10 23:06:00 +01:00
parent 39869d605c
commit 87d47f8ce8
11 changed files with 125 additions and 43 deletions

View File

@ -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 {