-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from huntmori/12-get-profile-implement
12 get profile implement
- Loading branch information
Showing
18 changed files
with
440 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
namespace App\Application\Common\model; | ||
|
||
use JsonSerializable; | ||
|
||
class JwtClaim implements JsonSerializable | ||
{ | ||
public ?string $userId; | ||
public ?string $profileUid; | ||
public ?int $exp; | ||
|
||
public function init(string $userId, string $profileUid, int $exp) : JwtClaim | ||
{ | ||
$this->userId = $userId; | ||
$this->profileUid = $profileUid; | ||
$this->exp = $exp; | ||
|
||
return $this; | ||
} | ||
|
||
public function initFromArray(array $claim) : JwtClaim | ||
{ | ||
$this->init( | ||
$claim['userId'], | ||
$claim['profileUid'], | ||
$claim['exp'] | ||
); | ||
|
||
return $this; | ||
} | ||
|
||
public function toArray() : array | ||
{ | ||
return [ | ||
'userId'=>$this->userId, | ||
'profileUid'=>$this->profileUid, | ||
'exp'=> $this->exp | ||
]; | ||
} | ||
|
||
public function jsonSerialize(): array | ||
{ | ||
return $this->toArray(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
namespace App\Application\Common\service; | ||
|
||
use App\Application\Common\model\JwtClaim; | ||
|
||
interface TokenService | ||
{ | ||
public function getUserIdFromToken(string $token); | ||
public function getProfileUidFromToken(string $token); | ||
public function getClaimFromToken(string $token) : ?JwtClaim; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
namespace App\Application\Common\service; | ||
|
||
use App\Application\Common\MemberPasswordEncrypt; | ||
use App\Application\Common\model\JwtClaim; | ||
use App\Application\Middleware\JwtHandler; | ||
use Psr\Log\LoggerInterface; | ||
|
||
class TokenServiceImplement implements TokenService | ||
{ | ||
private ?MemberPasswordEncrypt $passwordEncrypt; | ||
private ?JwtHandler $jwtHandler; | ||
private ?LoggerInterface $logger; | ||
|
||
public function __construct( | ||
MemberPasswordEncrypt $passwordEncrypt, | ||
JwtHandler $jwtHandler, | ||
LoggerInterface $logger | ||
) { | ||
$this->passwordEncrypt = $passwordEncrypt; | ||
$this->logger = $logger; | ||
$this->jwtHandler = $jwtHandler; | ||
} | ||
|
||
public function getUserIdFromToken(string $token) : string | ||
{ | ||
$decodedToken = $this->passwordEncrypt->decrypt($token); | ||
$decryptedJwt = $this->jwtHandler->decryptToken($decodedToken); | ||
$claims = $this->jwtHandler->decodeJwt($decryptedJwt); | ||
|
||
return $claims->userId; | ||
} | ||
|
||
public function getProfileUidFromToken(string $token) : string | ||
{ | ||
$decodedToken = $this->passwordEncrypt->decrypt($token); | ||
$decryptedJwt = $this->jwtHandler->decryptToken($decodedToken); | ||
$claims = $this->jwtHandler->decodeJwt($decryptedJwt); | ||
|
||
return $claims->profileUid; | ||
} | ||
|
||
public function getClaimFromToken(string $token) : ?JwtClaim | ||
{ | ||
$decodedToken = $this->passwordEncrypt->decrypt($token); | ||
$decryptedJwt = $this->jwtHandler->decryptToken($decodedToken); | ||
return $this->jwtHandler->decodeJwt($decryptedJwt); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.