fragotesac/zf1-2fa

Zend Framework 1 2FA component

0.0.1 2025-01-15 00:20 UTC

This package is not auto-updated.

Last update: 2025-01-15 16:06:36 UTC


README

This PHP library provides two-factor authentication (2FA) functionality for Zend Framework 1 applications. It allows for secure user login by requiring an additional step of verification, enhancing application security.

How to Use

Backend Configuration

  1. Create an Action:
    Implement an action in your backend where 2FA will be handled.

  2. Instantiate the 2FA Service:

    $this->tfa = new \Zend\TwoFactorAuth();
  1. Set Mail Configuration:
    $this->tfa->setMailConfig([
        'transport' => [],      // Mail transport settings
        'subject'   => '',      // Email subject for 2FA codes
        'from'      => ['email' => '', 'name' => ''],  // Sender details
        'template'  => []       // Email template configuration
    ]);
  1. Initialize the 2FA Service: Call the init method with a callback function to validate the user:
    $this->tfa->init([$this, 'checkUser']);
  1. Implement the checkUser Method: This method should handle user validation and error management using Zend\Util\ResponseUtil.

Client-Side Setup

  1. Copy the Client Folder:
    Copy the 2fa-client folder located inside src and place it in your public/js/ directory.

  2. Initialize the 2FA Client:
    Use the following JavaScript code to initialize the 2FA client:

   zfTwoFactorAuth.init(apiUrl, data, 'glass-theme', (loginFormData, url) => {
        // Handle the login callback here
   });
  • apiUrl: The API endpoint previously created for 2FA.
  • data: The login form fields converted into an object, e.g., {username: 'joe', password: 123456}.
  • glass-theme: The style theme for the 2FA modal. Available themes are: glass-theme cds-theme
  • Callback Function: Handles the login URL and sanitized parameters.

Requirements

  • Zend Framework 1
  • PHP 8.0 or higher
  • Composer for dependency management

Installation

   composer require fragotesac/zf1-2fa