Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Token Bundle Laravel Package

ecourty/token-bundle

Symfony bundle to manage secure, typed, revocable tokens for any Doctrine entity (password resets, email verification, share links). Supports expiry, single-use/max-uses, JSON payloads, events, subject resolution, and a purge command.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Symfony/Laravel Compatibility: The package is a Symfony bundle, not a Laravel package. While Laravel can technically integrate Symfony bundles via Symfony Bridge or Lumen, this introduces complexity and is not idiomatic. The package’s reliance on Doctrine ORM (v3.0+) and Symfony’s event system makes it a poor fit for Laravel’s Eloquent-based ecosystem.
  • Core Use Case Alignment: The package excels at token management (password resets, email verification, share links) but assumes a Symfony-centric architecture (e.g., #[RequiresToken] attributes, Symfony events, and dependency injection). Laravel’s middleware and service container would require significant adaptation.
  • Laravel Alternatives: Laravel already has mature solutions (e.g., Illuminate\Auth\Passwords\PasswordBroker, Laravel\Sanctum for tokens, or custom token services) that align better with its ecosystem.

Integration Feasibility

  • Doctrine ORM Dependency: Laravel uses Eloquent, not Doctrine. Migrating to Doctrine would require:
    • Installing doctrine/orm (compatibility issues with Laravel’s database layer).
    • Rewriting Eloquent models to Doctrine entities (e.g., implementing TokenSubjectInterface).
    • Adapting migrations and queries to Doctrine’s syntax.
  • Symfony-Specific Features:
    • #[RequiresToken] attributes → Laravel uses middleware or route filters.
    • Symfony events → Laravel uses event listeners (Illuminate\Events\Dispatcher).
    • Console commands → Laravel’s Artisan is compatible, but the token:purge command would need adaptation.
  • Token Storage: The bundle assumes a tokens table with specific columns (e.g., token, type, subject_id, expires_at). Laravel’s Eloquent would need a custom model to map this structure.

Technical Risk

Risk Area Severity Mitigation Strategy
Doctrine vs. Eloquent High Avoid Doctrine; build a Laravel-compatible token service from scratch or adapt the bundle’s logic.
Symfony Dependency Injection High Replace Symfony services (TokenManager) with Laravel service providers or facades.
Attribute-Based Routing Medium Replace #[RequiresToken] with Laravel middleware.
Event System Low Laravel’s event system is compatible; minor adjustments needed.
Migration Complexity Medium Create a custom migration for the tokens table using Laravel’s schema builder.

Key Questions for TPM

  1. Why Laravel?

    • Is the team already invested in Symfony, or is Laravel a hard requirement? If Symfony is an option, this bundle is a direct fit.
    • Are there existing Laravel token solutions (e.g., Sanctum, custom implementations) that could be extended instead?
  2. Token Use Cases

    • What specific token types are needed (e.g., password resets, email verification, share links)?
    • Are there non-Symfony dependencies (e.g., Twig templates for token emails) that would complicate integration?
  3. Performance Requirements

    • Will tokens be high-volume (e.g., millions of daily resets)? The bundle’s race-safe atomic increments for multi-use tokens may need benchmarking.
    • Is the token:purge command critical for cleanup, or can Laravel’s queue-based job handling suffice?
  4. Security Review

    • How are tokens generated (cryptographically secure)? The bundle uses Symfony’s Random component—Laravel’s Str::random() is equivalent.
    • Are there custom payloads or sensitive data attached to tokens that require encryption?
  5. Long-Term Maintenance

    • The package has no dependents and a single maintainer. Is this a risk for adoption?
    • Would a Laravel fork of this bundle be viable, or should the team build a custom solution?

Integration Approach

Stack Fit

  • Laravel Incompatibility: This bundle is not natively Laravel-compatible. A TPM must decide between:
    1. Abandoning the bundle in favor of Laravel-native solutions (recommended for most teams).
    2. Adapting the bundle via Symfony Bridge or a custom Laravel wrapper (high effort, not recommended).
  • Alternative Laravel Packages:
    • Password Resets: Illuminate\Auth\Passwords\PasswordBroker (built-in).
    • Email Verification: Laravel\Fortify or Illuminate\Auth\Events\Verified.
    • Shareable Links: Custom Eloquent model with token column + middleware.
    • General Tokens: spatie/laravel-activitylog (for auditing) + custom token service.

Migration Path

If proceeding with integration (not recommended), the path would be:

  1. Symfony Bridge Setup (for Laravel 9+):
    • Install symfony/bridge and doctrine/orm.
    • Configure Laravel to load Symfony bundles (complex, anti-pattern).
  2. Doctrine Migration:
    • Create a tokens table via Laravel migration:
      Schema::create('tokens', function (Blueprint $table) {
          $table->id();
          $table->string('token')->unique();
          $table->string('type');
          $table->foreignId('subject_id')->constrained()->cascadeOnDelete();
          $table->string('subject_type'); // e.g., "App\Models\User"
          $table->timestamp('expires_at');
          $table->boolean('single_use')->default(false);
          $table->integer('max_uses')->nullable();
          $table->integer('uses_count')->default(0);
          $table->boolean('revoked')->default(false);
          $table->json('payload')->nullable();
          $table->timestamps();
      });
      
  3. Service Adaptation:
    • Replace TokenManager with a Laravel service provider:
      class TokenServiceProvider extends ServiceProvider {
          public function register() {
              $this->app->singleton(TokenManager::class, function ($app) {
                  return new TokenManager(
                      new EntityManager($app['db']),
                      new TokenRepository(),
                      // ...
                  );
              });
          }
      }
      
  4. Middleware for Token Protection:
    • Replace #[RequiresToken] with middleware:
      class VerifyTokenMiddleware {
          public function handle(Request $request, Closure $next) {
              $token = $request->header('X-Token');
              if (!$this->tokenManager->validate($token, 'share')) {
                  abort(403);
              }
              return $next($request);
          }
      }
      
  5. Event Listeners:
    • Adapt Symfony events to Laravel’s Event system:
      Event::listen(TokenCreatedEvent::class, function ($event) {
          // Custom logic
      });
      

Compatibility

  • Doctrine ORM: Incompatible. Laravel’s Eloquent would require a custom adapter or a separate tokens table with Eloquent models.
  • Symfony Components: Partially compatible (e.g., Random, EventDispatcher can be swapped for Laravel equivalents).
  • Console Commands: Compatible with minor adjustments (e.g., using Laravel’s Artisan command structure).

Sequencing

  1. Assess Feasibility: Confirm if Laravel is a hard requirement or if Symfony is an option.
  2. Prototype Core Logic: Extract token creation/consumption logic from the bundle and implement it in Laravel first.
  3. Build Middleware: Replace Symfony attributes with Laravel middleware.
  4. Test Edge Cases: Validate token revocation, expiration, and race conditions in a Laravel context.
  5. Performance Benchmark: Test with high token volumes (e.g., 10K+ tokens/hour).

Operational Impact

Maintenance

  • High Risk: The bundle is unmaintained (no stars, no dependents, single maintainer). Laravel integration would require custom forks or wrappers, increasing long-term maintenance burden.
  • Dependency Updates: Symfony 7.0+ and PHP 8.3+ dependencies may conflict with Laravel’s supported versions.
  • Bug Fixes: Any issues would require manual patching or forking.

Support

  • No Community: No GitHub discussions, issues, or documentation beyond the README.
  • Laravel-Specific Issues: Debugging would require deep knowledge of both Symfony and Laravel, increasing onboarding time for developers.
  • Vendor Lock-in: Custom adaptations would make future migrations to other frameworks difficult.

Scaling

  • Database Load: The tokens table could grow large with high-volume tokens. Consider:
    • Partitioning by expires_at or type.
    • Archiving consumed/revoked tokens to a separate table.
  • Token Generation: Cryptographic security must be maintained at scale (Laravel’s Str::random() is sufficient).
  • Race Conditions: The bundle’s atomic uses_count increments are race-safe, but Laravel’s Eloquent
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
besmartand-pro/php-quality-config
sentix/ai-chatbot
terminal42/code-quality-tools
codifyo/ts-generator-bundle
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity