- WIP on V 2.x which added a OAuth2 server
This commit is contained in:
commit
0271aec31b
12 files changed
+110
-87
No files matched your search
@@ -3,32 +3,30 @@
|
||||
namespace Ulmus\User\Authorize\Header;
|
||||
|
||||
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\Authorize;
|
||||
use Ulmus\User\Lib\Authenticate;
|
||||
|
||||
class BearerMethod implements MethodInterface
|
||||
{
|
||||
protected JsonWebTokenDecoder $jwt;
|
||||
|
||||
public function __construct(
|
||||
protected UserInterface $user,
|
||||
# protected Authenticate $authorize,
|
||||
# protected UserInterface $user,
|
||||
protected string $token
|
||||
) {}
|
||||
|
||||
public function execute(ServerRequestInterface $request) : bool
|
||||
public function execute(ServerRequestInterface $request) : ServerRequestInterface
|
||||
{
|
||||
# $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']) ) {
|
||||
throw new \Exception("Given user id do not match with an existing/active user");
|
||||
}
|
||||
if ( $payload['sub'] ?? false) {
|
||||
$request = $request->withAttribute('authentication_middleware:user_id', $payload['sub']);
|
||||
}
|
||||
else {
|
||||
throw new \InvalidArgumentException("Given JsonWebToken is missing a 'sub' key (which concords to user id)");
|
||||
@@ -41,8 +39,7 @@ class BearerMethod implements MethodInterface
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
return $this->user->loggedIn();
|
||||
return $request;
|
||||
}
|
||||
|
||||
public function autodetectTokenType() : BearerTokenTypeEnum
|
||||
@@ -55,9 +52,4 @@ class BearerMethod implements MethodInterface
|
||||
|
||||
return BearerTokenTypeEnum::UniqueKey;
|
||||
}
|
||||
|
||||
protected function userFromJWT() : UserInterface
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user