- Moved Authenticate to DI file def

This commit is contained in:
Dave Mc Nicoll committed 2025-03-28 13:37:38 +00:00
1 parent 23079e6040
commit d149e0a741
5 files changed
+22 -8

No files matched your search

+5 -3
View File
@@ -6,6 +6,7 @@ use Psr\Http\Message\ServerRequestInterface;
use Ulmus\User\Authorize\Bearer\JsonWebToken;
use Ulmus\User\Authorize\Bearer\JsonWebTokenDecoder;
use Ulmus\User\Entity\UserInterface;
use Ulmus\User\Lib\Authenticate;
use Ulmus\User\Lib\Authorize;
class BearerMethod implements MethodInterface
@@ -13,20 +14,21 @@ class BearerMethod implements MethodInterface
protected JsonWebTokenDecoder $jwt;
public function __construct(
protected Authenticate $authorize,
protected UserInterface $user,
protected string $token
) {}
public function execute(ServerRequestInterface $request) : bool
{
$this->authorize->user = $this->user;
switch($this->autodetectTokenType()) {
case BearerTokenTypeEnum::JsonWebToken:
$authorize = new Authorize($this->user);
$payload = $this->jwt->getPayload();
if ($payload['sub'] ?? false) {
if ( ! $authorize->logUser((int) $payload['sub']) ) {
if ( ! $this->authorize->logUser($payload['sub']) ) {
throw new \Exception("Given user id do not match with an existing/active user");
}
}