PHP code example of vulpes / access-token

1. Go to this page and download the library: Download vulpes/access-token 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/ */

    

vulpes / access-token example snippets




leServiceAccount = new Token\GoogleAccessToken;
$googleServiceAccount->setScopes(...scopes: 'https://www.googleapis.com/auth/pubsub');

$googleServiceAccount->generateToken();



iceAccount = new Token\AccessToken(
    payload: [
        'iss' => 'it\'s me',
        'sub' => 'my-id'
    ]
);

// you can set your own keys in the Token\AccessToken constructor, this is (optional)
$serviceAccount->generateKeys();

// you can save your newly generated public key (optional), and your private too (and it's ID)
$publicKey = $serviceAccount->getPublicKey();

// your token to pass for example via Bearer
$token = $serviceAccount->generateToken();

// On the other side, you can use Your public key to decode the token
$otherServiceAccount = new Token\AccessToken(public_key: $publicKey);

// And here you get you're payload
$payload = $otherServiceAccount->decodeToken($token);