PHP code example of almefy / client

1. Go to this page and download the library: Download almefy/client 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/ */

    

almefy / client example snippets


$client = new \Almefy\Client($_ENV['ALMEFY_KEY'], $_ENV['ALMEFY_SECRET']);

try {
    $enrollmentToken = $client->enrollIdentity('john.doe');
    
} catch (\Almefy\Exception\TransportException $e) {
    echo 'Could not connect to Almefy service: '.$e->getMessage();
}

try {
    $client->enrollIdentity('john.doe', array(
        'sendEmail' => true
        'sendEmailTo' => '[email protected]'
    ));
    
} catch (\Almefy\Exception\TransportException $e) {
    echo 'Could not connect to Almefy service: '.$e->getMessage();
}

// Get the JWT from header
$jwt = $request->headers->get('X-Almefy-Authorization');

// decode it
$token = $client->decodeJwt($jwt);

// $userRepository is any PHP class used for database queries 
$user = $userRepository->retrieveByUsername($token->getIdentifier());

// Check any internal business logic
if (!$user->isEnabled() || !$user->isSubscriptionActive()) {
    return false;
}

if (!$client->authenticate($token)) {
    // Authentication attempt could not be verified or is invalid
    return false;
}