PHP code example of cleaniquecoders / token-vault

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

    

cleaniquecoders / token-vault example snippets


use CleaniqueCoders\TokenVault\Traits\InteractsWithTokenVault;

class User extends Authenticatable
{
    use InteractsWithTokenVault;
}

use CleaniqueCoders\TokenVault\Enums\Provider;

$user = User::find(1);

$user->tokens()->create([
    'provider' => Provider::GitHub, // enum usage
    'type' => 'access_token',       // e.g., access_token, refresh_token
    'token' => 'ghp_xxxx',          // will be encrypted automatically
    'meta' => ['note' => 'GitHub Deploy Token'],
    'expires_at' => now()->addDays(30),
]);

$token = $user->tokens()->first();

$plainToken = $token->getDecryptedToken();

$token->getMaskedToken(); // e.g., "ghp_****abcd"

use CleaniqueCoders\TokenVault\Enums\Provider;

$githubToken = $user->tokens()
    ->where('provider', Provider::GitHub)
    ->latest()
    ->first();

$user->tokens()
    ->where('expires_at', '<', now())
    ->delete();

'token-vault.encryptor' => \App\Drivers\OpenSslEncryptor::class,
bash
php artisan vendor:publish --tag="token-vault-migrations"
php artisan migrate