f4php/checkmate

Checkmate is a user verification SDK for F4, a (really) lightweight web application framework

v0.1.3 2025-07-02 19:48 UTC

This package is auto-updated.

Last update: 2025-07-02 19:48:23 UTC


README

Checkmate is a user verification SDK for F4 that uses Twilio Verify API by default.

Checkmate implements a very simple F4\Checkmate\UserVerificationServiceInterface, so you can create your own drop-in replacement if needed.

Quick Start

$ composer require f4php/checkmate

SDK Architecture

Checkmate uses Guzzle to interact with external APIs to send and verify one-time authentication tokens using various channels.

This SDK supports F4\Checkmate\Adapter\AdapterInterface, which allows you to add seamless support for virtually any external provider.

The following constants MUST be defined in an F4 environment config class:

namespace F4;

class Config extends AbstractConfig
{
    // ...
    public string CHECKMATE_ADAPTER_CLASS = \F4\Checkmate\Adapter\TwilioAdapter::class; // the default adapter
    public string CHECKMATE_DEFAULT_CHANNEL = 'email'; // must be one of Adapter's supported channels, see below for channels supported by Twilio
    // ...
}

Additionally, Twilio integration requires that the following constants MUST be defined in an F4 environment config class:

namespace F4;

use F4\Config\SensitiveParameter;

class Config extends AbstractConfig
{
    // ...
    #[SensitiveParameter]
    public string TWILIO_ACCOUNT_SID = '...';
    #[SensitiveParameter]
    public string TWILIO_AUTH_TOKEN = '...';
    #[SensitiveParameter]
    public string TWILIO_VERIFY_SID = '...';
    // ...
}

TwilioAdapter supports the following channels: auto, call, email, sms, sna, whatsapp.

Simple example

use F4\Checkmate;

$checkmate = new Checkmate();

$checkmate->sendVerificationToken('email@address.com');
$booleanCheckResult = $checkmate->checkVerificationToken('email@address.com', '1234');

Advanced example

use F4\Checkmate;
use F4\Checkmate\Adapter\TwilioAdapter;
use Throwable;

$checkmate = new Checkmate()
  ->withAdapter(new TwilioAdapter()
    ->withOption('accountSid', '...')
    ->withOption('authToken', '...')
    ->withOption('verifySid', '...')
    ->withOption('defaultChannel', 'sms')
    ->on(Throwable::class, function(Throwable $exception) {
      // handle adapter exception
    })
  )
  ->on(Throwable::class, function(Throwable $exception) {
    // handle checkmate exception
  });

$checkmate->sendVerificationToken('+1234567890', 'whatsapp');
$booleanCheckResult = $checkmate->checkVerificationToken('+1234567890', '1234');