- WIP on v2.x authentication
This commit is contained in:
1 parent
0271aec31b
commit
0eaaf79ad8
6 files changed
+47
-27
No files matched your search
@@ -70,11 +70,11 @@ class JsonWebTokenDecoder
|
||||
public function isJWT() : bool
|
||||
{
|
||||
try {
|
||||
return $this->parse();
|
||||
return count(explode('.', $this->encoded)) === 3;
|
||||
}
|
||||
catch(\Throwable $t) {
|
||||
return false;
|
||||
}
|
||||
catch(\Throwable $t) {}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getPayload() : array
|
||||
|
||||
@@ -6,6 +6,7 @@ use Psr\Http\Message\ServerRequestInterface;
|
||||
use Ulmus\User\Authorize\Bearer\JsonWebTokenDecoder;
|
||||
use Ulmus\User\Entity\UserInterface;
|
||||
use Ulmus\User\Lib\Authenticate;
|
||||
use Ulmus\User\Lib\AuthenticationMethodEnum;
|
||||
|
||||
class BearerMethod implements MethodInterface
|
||||
{
|
||||
@@ -23,10 +24,15 @@ class BearerMethod implements MethodInterface
|
||||
|
||||
switch($this->autodetectTokenType()) {
|
||||
case BearerTokenTypeEnum::JsonWebToken:
|
||||
$this->jwt->decode();
|
||||
|
||||
$payload = $this->jwt->getPayload();
|
||||
|
||||
if ( $payload['sub'] ?? false) {
|
||||
$request = $request->withAttribute('authentication_middleware:user_id', $payload['sub']);
|
||||
$request = $request
|
||||
->withAttribute('authentication_middleware:method', AuthenticationMethodEnum::ForceLogin)
|
||||
->withAttribute('authentication_middleware:jwt', $payload)
|
||||
->withAttribute('authentication_middleware:user_id', $payload['sub']);
|
||||
}
|
||||
else {
|
||||
throw new \InvalidArgumentException("Given JsonWebToken is missing a 'sub' key (which concords to user id)");
|
||||
@@ -37,6 +43,8 @@ class BearerMethod implements MethodInterface
|
||||
case BearerTokenTypeEnum::UniqueKey:
|
||||
# @TODO
|
||||
break;
|
||||
|
||||
default:
|
||||
}
|
||||
|
||||
return $request;
|
||||
|
||||
@@ -62,7 +62,7 @@ class HeaderAuthentication implements AuthorizeMethodInterface
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
return $request->hasHeader('authorization');
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user