Skip to content

AuroraWebSoftware/filament-loginkit

Repository files navigation

Filament Loginkit

A flexible authentication kit for Filament that brings enhanced two-factor authentication, SMS login, and customizable login flows to your Laravel applications.

Table of Contents

Installation

First, install the package via Composer:

composer require aurorawebsoftware/filament-loginkit

Then, run the install command to set up configuration, migrations, assets, and required dependencies:

php artisan filament-loginkit:install

Add the plugin to your PanelProvider:

plugin(FilamentLoginKitPlugin::make())

To require two-factor authentication for all users, use the forced() method:

plugin(FilamentLoginKitPlugin::make()->forced())

User Model Changes

Make sure your User model implements the necessary properties and traits:

<?php

use AuroraWebSoftware\FilamentLoginKit\Traits\TwoFactorAuthenticatable;

class User extends Authenticatable
{
    use TwoFactorAuthenticatable;

    protected $fillable = [
        'phone_number',
        'two_factor_type',
        'is_2fa_required',
        'sms_login_code',
        'sms_login_expires_at',
        'two_factor_code',
        'two_factor_expires_at',
        'is_active',
        'whatsapp_login_code',
        'whatsapp_login_expires_at'
    ];

    protected $casts = [
        'email_verified_at' => 'datetime',
        'password' => 'hashed',
        'sms_login_expires_at' => 'datetime',
        'is_2fa_required' => 'boolean',
        'two_factor_expires_at' => 'datetime',
        'is_active'=>'boolean'
        'whatsapp_login_expires_at' => 'datetime',
    ];
}

Configuration

After publishing the config file, you can find it at config/filament-loginkit.php.

Login Methods

Enable/disable email and SMS login:

'email_login' => env('LOGINKIT_EMAIL_LOGIN_ENABLED', true),

'sms_login' => env('LOGINKIT_SMS_LOGIN_ENABLED', false),

Two-Factor Authentication

Set available two-factor methods: authenticator, email, sms

'options' => [
    \AuroraWebSoftware\FilamentLoginKit\Enums\TwoFactorType::authenticator,
    \AuroraWebSoftware\FilamentLoginKit\Enums\TwoFactorType::email,
    \AuroraWebSoftware\FilamentLoginKit\Enums\TwoFactorType::sms,
],

Features

Enable or disable registration, multi-tenancy, or generic error messages:

'enabled_features' => [
    'register' => false,
    'multi_tenancy' => false,
    'generic_errors' => false,
],

SMS Service

To enable SMS authentication, you must implement your own SMS service using the provided interface.

You can find the interface at:

AuroraWebSoftware\FilamentLoginKit\Contracts\SmsServiceInterface

First, create a class that implements this interface. For example:

namespace App\Services;

use AuroraWebSoftware\FilamentLoginKit\Contracts\SmsServiceInterface;

class SmsService implements SmsServiceInterface
{
    public function sendSms(string $phone, string $message): void
    {
        // Your SMS sending logic here
    }
}

Then, register your service in the configuration file:

// config/filament-loginkit.php
'sms_service_class' => \App\Services\SmsService::class,

Note: Your SMS service must implement all methods required by SmsServiceInterface.

Rate Limits

Limit login and 2FA attempts to prevent abuse:

'rate_limits' => [
    'sms' => [
        'max_requests' => 5,
        'per_minutes' => 1,
    ],
    'sms_resend' => [
        'max_requests' => 2,
        'per_minutes' => 1,
    ],
    'login' => [
        'max_requests' => 5,
        'per_minutes' => 1,
    ],
    'two_factor' => [
        'max_requests' => 5,
        'per_minutes' => 1,
    ],
],

Queues

Set whether notifications are queued:

'queue_notifications' => env('LOGINKIT_QUEUE_NOTIFICATIONS', true),
'email_queue' => env('LOGINKIT_EMAIL_QUEUE', 'filament-loginkit'),
'sms_queue' => env('LOGINKIT_SMS_QUEUE', 'filament-loginkit'),

The queue name used by Filament Loginkit is filament-loginkit.

To start the queue worker in Laravel, run the following command:

php artisan queue:work --queue=filament-loginkit

And more! Please check the config/filament-loginkit.php file for the full list of options.

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

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

About

No description, website, or topics provided.

Resources

License

Contributing

Security policy

Stars

Watchers

Forks

Sponsor this project

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages