Weave 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

Acgranter Symfony Authenticator Laravel Package

acgranter/acgranter-symfony-authenticator

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation Add the package via Composer:

    composer require acgranter/acgranter-symfony-authenticator
    

    Publish the configuration (if needed):

    php artisan vendor:publish --provider="Acgranter\SymfonyAuthenticator\SymfonyAuthenticatorServiceProvider"
    
  2. Basic Configuration Register the authenticator in config/auth.php under the guards section:

    'web' => [
        'driver' => 'session',
        'provider' => 'users',
        'authenticator' => \Acgranter\SymfonyAuthenticator\Authenticator::class,
    ],
    
  3. First Use Case: Login Flow Use the Symfony AuthenticatorInterface to handle login logic in a controller or middleware:

    use Acgranter\SymfonyAuthenticator\Authenticator;
    
    public function login(Request $request, Authenticator $authenticator)
    {
        $credentials = $request->validate([
            'email' => 'required|email',
            'password' => 'required',
        ]);
    
        $user = User::where('email', $credentials['email'])->first();
    
        if (!$authenticator->authenticate($user, $credentials['password'])) {
            return back()->withErrors(['email' => 'Invalid credentials']);
        }
    
        // Redirect or proceed
    }
    

Implementation Patterns

Workflow: Authentication Pipeline

  1. Dependency Injection Inject Authenticator into controllers, middleware, or services:

    public function __construct(private Authenticator $authenticator) {}
    
  2. Custom Auth Logic Extend the authenticator for custom rules:

    use Acgranter\SymfonyAuthenticator\Authenticator as BaseAuthenticator;
    
    class CustomAuthenticator extends BaseAuthenticator
    {
        public function authenticate(User $user, string $password): bool
        {
            if (!$user->isActive()) {
                return false;
            }
            return parent::authenticate($user, $password);
        }
    }
    
  3. Integration with Laravel’s Auth Use the package alongside Laravel’s built-in auth:

    if (Auth::attempt($credentials)) {
        $authenticator->authenticate(Auth::user(), $credentials['password']);
        // Proceed
    }
    
  4. Middleware for Protected Routes Create middleware to enforce authentication:

    public function handle(Request $request, Closure $next)
    {
        if (!$request->user() || !$this->authenticator->isAuthenticated($request->user())) {
            abort(403);
        }
        return $next($request);
    }
    

Gotchas and Tips

Pitfalls

  1. Session Dependency The package relies on Symfony’s SessionInterface. Ensure your Laravel app has session configured (default is enabled).

    • Fix: Verify SESSION_DRIVER in .env (e.g., SESSION_DRIVER=file).
  2. Password Hashing Mismatch The package assumes Symfony’s password hashing. If using Laravel’s Hash::make(), ensure consistency:

    • Tip: Use Symfony\Component\Security\Core\Encoder\EncoderFactory or bridge Laravel’s hashing.
  3. User Provider Conflicts The authenticator expects a Symfony UserProviderInterface. Laravel’s Illuminate\Contracts\Auth\Authenticatable may need adaptation:

    • Solution: Implement Symfony\Component\Security\Core\User\UserInterface in your User model.

Debugging

  • Enable Debug Mode Set APP_DEBUG=true in .env to log authenticator errors.
  • Check Authenticator Events Listen for authenticator.login.success or authenticator.login.failure events (if extended).

Extension Points

  1. Custom User Check Override Authenticator::supports() to filter supported user classes:

    public function supports(UserInterface $user): bool
    {
        return $user instanceof CustomUser;
    }
    
  2. Token-Based Auth Extend for API tokens by implementing Symfony\Component\Security\Core\Authentication\Token\TokenInterface.

  3. Rate Limiting Combine with Laravel’s throttle middleware to limit login attempts:

    Route::middleware(['throttle:5,1'])->group(...);
    

Configuration Quirks

  • Default Guard The package defaults to the web guard. Specify a custom guard in config/auth.php:
    'api' => [
        'driver' => 'session',
        'provider' => 'users',
        'authenticator' => \Acgranter\SymfonyAuthenticator\Authenticator::class,
    ],
    
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.
adachsoft/changelog-linter
adachsoft/collection
payerurl/telegrambot-crypto-payment-instant-payout
dskripchenko/laravel-hybrid-search
riorizkyrainey/lara-ced
mehedimi/static-vel
zharp/zharp
nonsapiens/bigquery-model-sync
lgu-bayambang-ict-office/lgu-laravel-development-standards
andydefer/laravel-support
se7enxweb/flysystem
lampwick/laravel
jeslage/statamic-emojis
micahdshackelford/rmap-laravel
draftsmaninc/draftsman
square-bit/laravel-volition
himito/laravel-mailman
htinlynn/genius-helper
maco-studios/hephaestus
elmogy/larafast