PHP code example of surfnet / yubikey-api-client-bundle
1. Go to this page and download the library: Download surfnet/yubikey-api-client-bundle 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/ */
surfnet / yubikey-api-client-bundle example snippets
public function registerBundles()
{
$bundles[] = new Surfnet\YubikeyApiClientBundle\SurfnetYubikeyApiClientBundle;
}
public function fooAction()
{
/** @var \Surfnet\YubikeyApiClientBundle\Service\VerificationService */
$service = $this->get('surfnet_yubikey_api_client.verification_service');
if (!\Surfnet\YubikeyApiClient\Otp::isValid('user-input-otp-here')) {
// User-entered OTP string is not valid.
}
$otp = \Surfnet\YubikeyApiClient\Otp::fromString('user-input-otp-here');
$result = $service->verify($otp);
if ($result->isSuccessful()) {
// Yubico verified OTP.
}
}