Refactored out claim check logic to its own class
This commit is contained in:
46
src/Broker/Security/ClaimChecker.php
Normal file
46
src/Broker/Security/ClaimChecker.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace NoccyLabs\Mercureact\Broker\Security;
|
||||
|
||||
use NoccyLabs\SimpleJWT\JWTToken;
|
||||
use Rize\UriTemplate\UriTemplate;
|
||||
|
||||
class ClaimChecker
|
||||
{
|
||||
private UriTemplate $uriTemplate;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->uriTemplate = new UriTemplate();
|
||||
}
|
||||
|
||||
public function matchAll(array $topics, array $claims): bool
|
||||
{
|
||||
$matched = 0;
|
||||
foreach ((array)$topics as $match) {
|
||||
foreach ($claims as $claim) {
|
||||
if (($claim === "*")
|
||||
|| ($claim === $match)
|
||||
|| ($this->uriTemplate->extract($claim, $match, true))) {
|
||||
$matched++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ($matched == count($topics));
|
||||
}
|
||||
|
||||
public function matchOne(array $topics, array $claims): bool
|
||||
{
|
||||
foreach ((array)$topics as $match) {
|
||||
foreach ($claims as $claim) {
|
||||
if (($claim === "*")
|
||||
|| ($claim === $match)
|
||||
|| ($this->uriTemplate->extract($claim, $match, true))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user