Created
March 14, 2021 12:01
-
-
Save cesurapp/edcd755f7fa3c57269004920f662fd73 to your computer and use it in GitHub Desktop.
JWT Custom User Key
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
<?php | |
$userHashKey = 'password'; | |
$privateUserPayloadData = [ | |
'userId' => 1, | |
'exp' => (new \DateTime('+5 hours'))->getTimestamp() | |
]; | |
// Generate Token | |
$token = JWT::encode($privateUserPayloadData, $userHashKey,'HS256'); | |
dump('Private Token => ' . $token); | |
// Decode Token | |
// Find UserId | |
$payload = json_decode(base64_decode(explode(".", $token)[1]), true); | |
dump('Token Find UserId => ' . $payload['userId']); | |
// Verify | |
//$userHashKey = $this->getUserPassword($payload['userId']); | |
JWT::decode($token, $userHashKey, ['HS256']); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment