A secure and extensible token manager for Laravel, designed to store, encrypt, and decrypt tokens or API keys. This is useful when you are building an application that require to store sensitive information.
You can install the package via composer:
composer require cleaniquecoders/token-vault
You can publish and run the migrations with:
php artisan vendor:publish --tag="token-vault-migrations"
php artisan migrate
You can publish the config file with:
php artisan vendor:publish --tag="token-vault-config"
Here’s the updated Usage guide for your TokenVault
package, incorporating the Provider
enum and clarifying token types:
To allow a model (e.g. User
) to have tokens:
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();
⚠️ Only use this when absolutely necessary — avoid exposing raw tokens.
$token->getMaskedToken(); // e.g., "ghp_****abcd"
Use this for logs, audit trails, or safe UI display.
use CleaniqueCoders\TokenVault\Enums\Provider;
$githubToken = $user->tokens()
->where('provider', Provider::GitHub)
->latest()
->first();
$user->tokens()
->where('expires_at', '<', now())
->delete();
To use a custom encryption method:
'token-vault.encryptor' => \App\Drivers\OpenSslEncryptor::class,
And the class need to implements the \CleaniqueCoders\TokenVault\Contracts\Encryptor
interface.
composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.