PHP code example of harlam / auth-secret-keys

1. Go to this page and download the library: Download harlam/auth-secret-keys library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

harlam / auth-secret-keys example snippets


/** Initialize keys storage */
$keysStorage = new KeysStorage('/tmp/storage/secret-keys');

$keysManager = new KeysManager($keysStorage, new BaseGenerator());

/* Validation max attempts (default 3) */
$keysManager->setValidationMaxAttempts(5);

/* Secret key lifetime (default 300 sec.) */
$keysManager->setValidationMaxLifetime(300);

/* Secret key generation request interval (default 60 sec.) */
$keysManager->setRequestInterval(15);

/* Static keys (default empty) */
$keysManager->setPresetKeys(['owner' => 'static-secret']);

/** Generate secret key with owner */
$key = $keysManager->generate('owner');

/** Or validate secret key */
$key = (new KeyEntity)
    ->setOwner('owner')
    ->setKey('secret');

$keysManager->validate($key);