Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

🔑 💚 Keysmith Vue is a Laravel 12 + Vue 3 package for managing API tokens with Laravel Sanctum. It provides pre-built Vue components for generating, viewing, and revoking API keys, offering a seamless and user-friendly authentication experience.

License

NotificationsYou must be signed in to change notification settings

Blaspsoft/keysmith-vue

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Blasp Icon

Total DownloadsLatest VersionLicense

Keysmith Vue - Laravel 12 Vue Starterkit API Token Management

Keysmith Vue is a Laravel 12 Vue Starterkit package that provides Vue.js components for managing API keys and tokens in your application. It offers a clean, user-friendly interface for creating, viewing, and revoking API keys with customizable permissions based on the implementation from Laravel Breeze.

Features

  • 🔑 Easy API token generation and management
  • 🔒 Built on Laravel Sanctum's secure token authentication
  • 🎨 Pre-built Vue components for quick integration
  • 📱 Responsive and user-friendly interface
  • ⚙️ Flexible installation options (page or settings templates)
  • 🛠️ Customizable permissions system

Requirements

  • PHP 8.2 or higher
  • Laravel 12.x
  • Vue 3.x
  • Laravel Sanctum

Installation

You can install the package via composer:

composer require blaspsoft/keysmith-vue

Choose your preferred installation template:

Page Template

Install this option to add a dedicated API tokens page atpages/api-tokens/index.vue. This provides a standalone interface for managing your API tokens.

Settings Template

Choose this option to integrate API token management within your Laravel Vue Starterkit settings atpages/settings/APITokens.vue. This keeps token management alongside your other application settings.

Run one (or both) of the following commands based on your choice:

php artisan keysmith:install page

or

php artisan keysmith:install settings

Configure Inertia Middleware

Add the following to yourHandleInertiaRequests.php middleware'sshare method to handle API token flash messages:

'flash' => ['api_token' =>fn () =>session()->get('api_token'),],
publicfunctionshare(Request$request):array    {        [$message,$author] =str(Inspiring::quotes()->random())->explode('-');return [            ...parent::share($request),'name' =>config('app.name'),'quote' => ['message' =>trim($message),'author' =>trim($author)],'auth' => ['user' =>$request->user(),            ],'flash' => ['api_token' =>fn () =>session()->get('api_token'),            ],        ];    }

This configuration is required to display newly created API tokens to users.

Add navlinks to starterkit templates

Dependent of which template you decide to use 'page" or "settings" (or both). You may want to add links to the app sidebar and settings navigations.

For the page updatejs/components/AppSidebar.vue

constmainNavItems:NavItem[]=[{title:"Dashboard",href:"/dashboard",icon:LayoutGrid,},{title:"API Tokens",href:"/api-tokens",icon:KeyRound,},];

For the settings updatejs/layouts/settings/Layout.vue

constsidebarNavItems:NavItem[]=[{title:"Profile",href:"/settings/profile",},{title:"Password",href:"/settings/password",},{title:"Appearance",href:"/settings/appearance",},{title:"API Tokens",href:"/settings/api-tokens",},];

Publish config [optional]

php artisan vendor:publish --tag=keysmith-vue-config --force

This command will publish a configuration file atconfig/keysmith.php, where you can customize keysmith settings.

Dependencies

This package requires Laravel Sanctum for API token authentication. Before using Keysmith Vue, make sure to:

  1. Install Laravel Sanctum:
composer require laravel/sanctum
  1. Publish and run Sanctum's migrations:
php artisan vendor:publish --provider="Laravel\Sanctum\SanctumServiceProvider" --tag="sanctum-migrations"php artisan migrate
  1. Add the HasApiTokens trait to your User model:
useLaravel\Sanctum\HasApiTokens;class Userextends Authenticatable{use HasApiTokens;// ... existing code ...}

Components

Keysmith Vue provides two components that are installed in your/components directory:

  • CreateApiTokenForm.vue: Form component for generating new API tokens
  • ManageApiTokens.vue: Component for viewing and managing existing tokens

These components are utilized in both the page and settings templates.

Routes

Keysmith Vue provides two sets of routes depending on your installation choice:

Page Template Routes

If you installed using the page template (keysmith:install page), these routes are available:

Route::get('/api-tokens', [TokenController::class,'index'])->name('api-tokens.index');Route::post('/api-tokens', [TokenController::class,'store'])->name('api-tokens.store');Route::put('/api-tokens/{token}', [TokenController::class,'update'])->name('api-tokens.update');Route::delete('/api-tokens/{token}', [TokenController::class,'destroy'])->name('api-tokens.destroy');

Settings Template Routes

If you installed using the settings template (keysmith:install settings), these routes are available:

Route::get('/settings/api-tokens', [TokenController::class,'index'])->name('settings.api-tokens.index');Route::post('/settings/api-tokens', [TokenController::class,'store'])->name('settings.api-tokens.store');Route::put('/settings/api-tokens/{token}', [TokenController::class,'update'])->name('settings.api-tokens.update');Route::delete('/settings/api-tokens/{token}', [TokenController::class,'destroy'])->name('settings.api-tokens.destroy');

All routes are protected by authentication middleware and handle the following operations:

  • GET: Retrieve all tokens for the authenticated user
  • POST: Create a new API token
  • PUT: Update token permissions
  • DELETE: Revoke an existing token

Testing

Keysmith Vue includes test files that are placed in your project'stests/Feature/ApiToken directory:

  • PageTokenTest.php: Tests for the page template implementation
  • SettingsTokenTest.php: Tests for the settings template implementation

You can run the tests using:

php artisantest

Customizing Permissions

You can customize the available token permissions by modifying theconfig/keysmith.php file:

return ['permissions' => ['read','create','update','delete',// Add your custom permissions here    ],];

Screenshots

keysmithkeysmithkeysmithkeysmithkeysmithkeysmithkeysmith

Security

If you discover any security related issues, please emailmike.deeming@blaspsoft.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please seeLicense File for more information.

About

🔑 💚 Keysmith Vue is a Laravel 12 + Vue 3 package for managing API tokens with Laravel Sanctum. It provides pre-built Vue components for generating, viewing, and revoking API keys, offering a seamless and user-friendly authentication experience.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp