mirror of
https://gitee.com/ctexthuang/hyperf_rbac_framework_server_ctexthuang.git
synced 2025-12-25 17:07:49 +08:00
feat : jwt
This commit is contained in:
@@ -11,6 +11,7 @@ use Lcobucci\JWT\Builder;
|
||||
use Lcobucci\JWT\JwtFacade;
|
||||
use Lcobucci\JWT\Signer;
|
||||
use Lcobucci\JWT\Signer\Key;
|
||||
use Lcobucci\JWT\Token\RegisteredClaims;
|
||||
use Lcobucci\JWT\UnencryptedToken;
|
||||
use Lcobucci\JWT\Validation\Constraint;
|
||||
use Lcobucci\JWT\Validation\Constraint\SignedWith;
|
||||
@@ -45,7 +46,8 @@ abstract class AbstractJwt implements JwtInterface
|
||||
$this->getSigner(),
|
||||
$this->getSigningKey(),
|
||||
function (Builder $builder, \DateTimeImmutable $immutable) use ($sub, $callable) {
|
||||
$builder = $builder->identifiedBy($sub);
|
||||
$builder = $builder->identifiedBy($sub)
|
||||
->issuedBy($this->getConfig('claims.'.RegisteredClaims::ISSUER,''));
|
||||
if ($callable !== null) {
|
||||
$builder = $callable($builder);
|
||||
}
|
||||
@@ -65,8 +67,10 @@ abstract class AbstractJwt implements JwtInterface
|
||||
$this->getSigner(),
|
||||
$this->getSigningKey(),
|
||||
function (Builder $builder, \DateTimeImmutable $immutable) use ($sub, $callable) {
|
||||
$builder = $builder->identifiedBy($sub);
|
||||
$builder = $builder->expiresAt($this->getRefreshExpireAt($immutable));
|
||||
$builder = $builder->identifiedBy($sub)
|
||||
->issuedBy($this->getConfig('claims.'.RegisteredClaims::ISSUER,''))
|
||||
->expiresAt($this->getRefreshExpireAt($immutable));
|
||||
|
||||
if ($callable !== null) {
|
||||
$builder = $callable($builder);
|
||||
}
|
||||
@@ -81,6 +85,7 @@ abstract class AbstractJwt implements JwtInterface
|
||||
*/
|
||||
public function parserAccessToken(string $accessToken): UnencryptedToken
|
||||
{
|
||||
echo 1;
|
||||
return $this->getJwtFacade()
|
||||
->parse(
|
||||
$accessToken,
|
||||
|
||||
14
app/Lib/Jwt/RequestScopedTokenTrait.php
Normal file
14
app/Lib/Jwt/RequestScopedTokenTrait.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Lib\Jwt;
|
||||
|
||||
use Hyperf\Context\RequestContext;
|
||||
use Lcobucci\JWT\UnencryptedToken;
|
||||
|
||||
trait RequestScopedTokenTrait
|
||||
{
|
||||
public function getToken(): ?UnencryptedToken
|
||||
{
|
||||
return RequestContext::get()->getAttribute('token');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user