blaspsoft/token-forge
Composer 安装命令:
composer require blaspsoft/token-forge
包简介
Token Forge brings Laravel Jetstream token management over to Laravel Breeze
关键字:
README 文档
README
Token Forge - API Token Management for Laravel Breeze
blaspsoft/token-forge is a Laravel package that adds robust, customizable API token management to your application, inspired by Laravel Jetstream. Token Forge allows you to create, manage, and monitor API tokens with ease, providing secure access control for your API.
Note: This package supports both the Blade and Inertia Vue Laravel Breeze stacks.
Features
- Generate and manage API tokens for users
- Define token permissions for precise access control
- Monitor token activity and revoke tokens when necessary
- Seamlessly integrates with Laravel’s authentication and session management
- Uses a contract (
TokenForgeControllerinterface) for flexibility and stack-specific implementation
Requirements
This package requires the following dependencies:
- Laravel Breeze: Must use the Blade or Inertia Vue stack for front-end support.
- Laravel Sanctum: Provides token-based authentication for API tokens.
Install Laravel Breeze with the relevant stack:
# For Blade stack: composer require laravel/breeze --dev php artisan breeze:install blade # For Vue-Inertia stack: composer require laravel/breeze --dev php artisan breeze:install vue
Install Laravel Sanctum:
composer require laravel/sanctum php artisan install:api php artisan migrate
Then install the front-end dependencies:
npm install npm run dev
Installation
Install the package via Composer:
composer require blaspsoft/token-forge
After installing the package, publish the configuration file:
php artisan vendor:publish --tag=token-forge-config --force
This command will publish a configuration file at config/token-forge.php, where you can customize Token Forge settings.
Setup Instructions
1. Install the Stack
Depending on your Laravel Breeze stack, run the appropriate command to install Token Forge:
-
For Blade stack:
php artisan token-forge:install blade
-
For Vue-Inertia stack:
php artisan token-forge:install vue
This command will:
- Copy the appropriate controller (
BladeTokenControllerorVueTokenController) to yourapp/Http/Controllersdirectory. - Automatically bind the
TokenForgeControllerinterface to the correct implementation.
2. Sanctum Setup
Ensure that Laravel Sanctum is properly configured. Make sure the HasApiTokens trait is added to your User model:
use Laravel\Sanctum\HasApiTokens; class User extends Authenticatable { use HasApiTokens, Notifiable; }
Additionally, ensure that Sanctum's setup command is run to install its configuration and migrations:
php artisan install:api php artisan migrate
3. Middleware Configuration (Inertia Vue Only)
To ensure that Token Forge integrates smoothly with your Inertia responses, modify your HandleInertiaRequest.php middleware file as follows:
Add the following block to the share method in app/Http/Middleware/HandleInertiaRequest.php:
public function share(Request $request): array { return [ ...parent::share($request), 'auth' => [ 'user' => $request->user(), ], 'flash' => [ 'tokenForge' => [ 'token' => fn () => session()->get('token'), ], ], ]; }
This setup enables Token Forge to flash token information to your Inertia responses, allowing you to use the token in your Vue components.
4. API Token Management Routes
The routes provided by Token Forge implement the TokenForgeController interface, allowing flexibility for different stacks. The interface is automatically resolved to the correct implementation (Blade or Vue) based on the installation.
Here are the available routes:
| Method | URI | Interface Method | Description |
|---|---|---|---|
| GET | /api-tokens |
index |
Display the API tokens list |
| POST | /api-tokens |
store |
Create a new API token |
| PUT | /api-tokens/{token} |
update |
Update an existing API token |
| DELETE | /api-tokens/{token} |
destroy |
Delete an API token |
These routes provide a complete interface to generate, view, and revoke API tokens through a consistent REST API.
Configuration
The package configuration is located in config/token-forge.php. Here are the default values:
Default Permissions
'default_permissions' => [ 'read', ],
These are the default permissions assigned to new API tokens if no specific permissions are provided during creation.
Available Permissions
'available_permissions' => [ 'create', 'read', 'update', 'delete', ],
These are the permissions available to assign to API tokens. You can modify these values to fit your application’s needs.
If you wish to change the default or available permissions, publish the configuration file using:
php artisan vendor:publish --tag=token-forge-config --force
Then, update the config/token-forge.php file to reflect your desired permissions.
Final Step: Build Assets
After completing the setup, ensure your front-end assets are compiled. You can use one of the following commands:
-
For development:
npm run dev
-
For production:
npm run build
This will ensure the necessary assets are available for the API token management UI.
Screenshots
License
This package is open-source software licensed under the MIT license.
blaspsoft/token-forge 适用场景与选型建议
blaspsoft/token-forge 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 745 次下载、GitHub Stars 达 35, 最近一次更新时间为 2024 年 11 月 14 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「blaspsoft」 「token-forge」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 blaspsoft/token-forge 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 blaspsoft/token-forge 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 blaspsoft/token-forge 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Blasp is a powerful and customisable profanity filter package for Laravel applications
Onym is a lightweight Laravel package designed to generate unique, structured, and meaningful filenames effortlessly.
Doxswap is a simple document conversion package for Laravel which uses LibreOffice to convert documents to a variety of formats.
SocialitePlus is a Laravel package that simplifies social authentication by extending Laravel Socialite. It provides predefined Google, Facebook, GitHub, and LinkedIn login options for seamless integration into Laravel 12 Vue and React Starter Kits
A React & Inertia-powered API key management system for Laravel 12 React Starterkit, with secure token generation, revocation, and authentication.
A Vue & Inertia-powered API key management system for Laravel 12 Vue Starterkit, with secure token generation, revocation, and authentication.
统计信息
- 总下载量: 745
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 35
- 点击次数: 27
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-11-14