stickee/laravel-2fa

Stickee Laravel 2FA - add two factor authentication

v1.0.7 2024-05-07 09:49 UTC

This package is auto-updated.

Last update: 2024-11-07 10:54:56 UTC


README

This a composer module for adding two factor authentication.

Contents

Quick Start

  1. composer require stickee/laravel-2fa
  2. php artisan migrate

2FA is now enabled, but not enforced. To enforce it for all users, set in your .env: LARAVEL_2FA_REQUIRED=true

Users will be prompted to enroll in 2FA when they log in.

Installation

composer require stickee/laravel-2fa

This module ships with a Laravel service provider which will be automatically registered for Laravel 5.5+.

Manual registration

The module can be manually registered by adding this to the providers array in config/app.php:

Stickee\Laravel2fa\ServiceProvider::class,

Configuration

Environment Variables

Config File

Publish the configuration file to your project with this command:

php artisan vendor:publish --provider=Stickee\\Laravel2fa\\ServiceProvider --tag=config

Customisation

The package is highly customisable - most parts can be swapped out for your own implementation if required.

How Do I...?

  • Change the templates
    • Publish the views to your project with php artisan vendor:publish --provider=Stickee\\Laravel2fa\\ServiceProvider --tag=laravel-views and edit them there.
  • Customise the text / add a translation
    • Publish the translations to your project with php artisan vendor:publish --provider=Stickee\\Laravel2fa\\ServiceProvider --tag=translations and edit them there.
  • Change the QR code generator
    • To change to one of the built-in BaconQrCode backends, change the config variable qr_code_generator. At the time of writing, supported backends are \BaconQrCode\Renderer\Image\ImagickImageBackEnd::class \BaconQrCode\Renderer\Image\SvgImageBackEnd::class \BaconQrCode\Renderer\Image\EpsImageBackEnd::class
    • To use something completely different, create a class implementing \Stickee\Laravel2fa\Contracts\QrCodeGenerator and bind it to that interface in your service provider
  • Create a custom driver / provider
    • Implement \Stickee\Laravel2fa\Contracts\Driver and register it in your laravel-2fa.drivers config. To make things easier you can probably extend \Stickee\Laravel2fa\Drivers\AbstractDriver.

Developing

The easiest way to make changes is to make the project you're importing the module in to load the module from your filesystem instead of the composer repository, like this:

  1. composer remove stickee/laravel-2fa
  2. Edit composer.json and add
    "repositories": [
            {
                "type": "path",
                "url": "../laravel-2fa"
            }
        ]
    
    where "../laravel-2fa" is the path to where you have this project checked out
  3. composer require stickee/laravel-2fa

NOTE: Do not check in your composer.json like this!