blaspsoft/keysmith-react 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

blaspsoft/keysmith-react

Composer 安装命令:

composer require blaspsoft/keysmith-react

包简介

A React & Inertia-powered API key management system for Laravel 12 React Starterkit, with secure token generation, revocation, and authentication.

README 文档

README

Blasp Icon

Total Downloads Latest Version License

Keysmith React - Laravel 12 React Starterkit API Token Management

Keysmith React is a Laravel 12 React Starterkit package that provides React.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 Laravel Breeze.

🎥 Keysmith React Video Tutorial

Watch the Tutorial

▶️ Click the image above to watch the tutorial on YouTube!

✨ Features

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

🛠 Requirements

Before installing Keysmith React, ensure your environment meets the following requirements:

  • PHP 8.0+
  • Laravel 12.x
  • React 19.x
  • Laravel Sanctum

🚀 Installation

Install the package via Composer:

composer require blaspsoft/keysmith-react

Choose Your Installation Template

You can install one (or both) of the available templates:

Page Template

Adds a dedicated API tokens page at pages/api-tokens/index.tsx.

php artisan keysmith:install page

Settings Template

Integrates API token management within the Laravel Vue Starterkit settings at pages/settings/api-tokens.tsx.

php artisan keysmith:install settings

🔧 Configuration

1️⃣ Configure Inertia Middleware

Add the following to your HandleInertiaRequests.php middleware's share method to enable API token flash messages:

'flash' => [
    'api_token' => fn () => session()->get('api_token'),
],

Full example:

public function share(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 ensures newly created API tokens are displayed to users.

2️⃣ Add Navigation Links

For the Page Template

Modify js/components/app-sidebar.tsx:

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

For the Settings Template

Modify js/layouts/settings/layout.tsx:

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

3️⃣ (Optional) Publish Configuration File

To customize settings, publish the config file:

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

This creates config/keysmith.php, where you can modify key permissions.

🔑 Dependencies

Keysmith React requires Laravel Sanctum for API token authentication.

  1. Install Laravel Sanctum:

    composer require laravel/sanctum
  2. Publish and run Sanctum’s migrations:

    php artisan vendor:publish --provider="Laravel\Sanctum\SanctumServiceProvider" --tag="sanctum-migrations"
    php artisan migrate
  3. Add the HasApiTokens trait to your User model:

    use Laravel\Sanctum\HasApiTokens;
    
    class User extends Authenticatable
    {
        use HasApiTokens;
        // ... existing code ...
    }

📦 Components

Keysmith React provides two main components located in /components:

  • create-api-token-form.tsx → Form for generating new API tokens
  • manage-api-tokens.tsx → Component for viewing and managing existing tokens

These components are used in both Page and Settings templates.

🌐 Routes

Keysmith uses the routes defined below:

Route::get('/settings/api-tokens', [TokenController::class, 'index'])->name('settings.api-tokens.index');
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');

🧪 Testing

Keysmith React includes tests in tests/Feature/ApiToken/:

Run the tests with:

php artisan test

🎛 Customizing Permissions

Modify the available API token permissions in config/keysmith.php:

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

🔒 Security

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

📜 Credits

📄 License

This package is licensed under MIT. See LICENSE.md for details.

blaspsoft/keysmith-react 适用场景与选型建议

blaspsoft/keysmith-react 是一款 基于 TypeScript 开发的 Composer 扩展包,目前已累计 269 次下载、GitHub Stars 达 9, 最近一次更新时间为 2025 年 03 月 10 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「blaspsoft」 「keysmith-react」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 blaspsoft/keysmith-react 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 blaspsoft/keysmith-react 我们能提供哪些服务?
定制开发 / 二次开发

基于 blaspsoft/keysmith-react 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 269
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 9
  • 点击次数: 33
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 9
  • Watchers: 3
  • Forks: 2
  • 开发语言: TypeScript

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-03-10