Skip to content

SURFnet/yubikey-api-client-bundle

Repository files navigation

Yubikey API Client Bundle

Build Status Scrutinizer Code Quality
develop Build Status Scrutinizer Code Quality
master Build Status Scrutinizer Code Quality

A Symfony bundle to integrate Yubikey's OTP validation service.

Installation

Add the bundle to your Composer file.

composer require 'surfnet/yubikey-api-client-bundle'

Add the bundle to your AppKernel.

public function registerBundles()
{
    $bundles[] = new Surfnet\YubikeyApiClientBundle\SurfnetYubikeyApiClientBundle;
}

Usage

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.
    }
}