Skip to content

Instantly share code, notes, and snippets.

@cesurapp
Created March 14, 2021 12:01
Show Gist options
  • Save cesurapp/edcd755f7fa3c57269004920f662fd73 to your computer and use it in GitHub Desktop.
Save cesurapp/edcd755f7fa3c57269004920f662fd73 to your computer and use it in GitHub Desktop.
JWT Custom User Key
<?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