PHP code example of freedomsex / jwt-manager

1. Go to this page and download the library: Download freedomsex/jwt-manager library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

freedomsex / jwt-manager example snippets


$manager = new JWTManager(
    '../keys/private.key',
    '../keys/public.key',
    $this->ttl
);

$token = $manager->create();

$token = $manager->create($user);
// getId - uid
// getRoles - roles
// getIdentityId - uuid
// getAccess - access
// getSubject -sub

$token = $manager->create($user);
// getId - id
// getUid - uid
// or
// getIdentityId - uid
 
// getId - id
// and
// getUid - uid (deprecated)
// and
// getIdentityId - uuid

$token = $manager->create($user, 1638549013); 

$payload = $manager->load($token); // object return
$payload = (array) $manager->load($token); // array return

[
  "uid" => 1
  "exp" => 1638549013
]

public function populatePayload(array $payload, $user = null): array