2017 © Pedro Peláez
 

library oath-server-suite

A collection of classes to provide second factor authentication like Yubico OTP (Yubikey), Oath (TOTP, HOTP, GoogleAuthenticator) server-side.

image

markenwerk/oath-server-suite

A collection of classes to provide second factor authentication like Yubico OTP (Yubikey), Oath (TOTP, HOTP, GoogleAuthenticator) server-side.

  • Monday, February 6, 2017
  • by bonscho
  • Repository
  • 1 Watchers
  • 2 Stars
  • 131 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 23 Versions
  • 14 % Grown

The README.md

PHP Oath Server Suite

Build Status Test Coverage Dependency Status SensioLabs Insight Code Climate Latest Stable Version Total Downloads License, (*1)

A collection of classes to provide second factor authentication like Yubico OTP (Yubikey), Oath (TOTP, HOTP, GoogleAuthenticator) server-side., (*2)

For more information about Oath check out https://openauthentication.org/., (*3)

More information about TOTP (Time-based One-time Password Algorithm) can be found at Wikipedia., (*4)

More information about HOTP (HMAC-based One-time Password Algorithm) can be found at Wikipedia., (*5)

For more information about the Yubico OTP authentication mechanism read the „What is YubiKey OTP?“ article at https://developers.yubico.com/OTP/., (*6)

Installation

```{json} { "require": { "chroma-x/oath-server-suite": "~4.0" } }, (*7)


## Usage ### Autoloading and namesapce ```{php} require_once('path/to/vendor/autoload.php');

Yubico OTP (YubiCloud)

To use Yubico OTP you need YubiCloud access. You can get free API credentials from https://upgrade.yubico.com/getapikey/., (*8)

Validating a Yubico one time password

```{php} use ChromaX\CommonException\NetworkException\Base\NetworkException;, (*9)

$otp = $_POST['otp']; $userPublicId = 'fetchedFromDatabaseOrSimilar';, (*10)

$validator = new OathServerSuite\Validation\YubicoOtp\Validator('yubiCloudClientId', 'yubiCloudSecretKey'); try { $validator->validate($otp, $userPublicId); if ($validator->isValid()) { // Validation was successful } else { // Validation failed } } catch (NetworkException $exception) { // Accessing the YubiCloud webservice failed. }, (*11)


--- ### Oath – Google Authenticator style #### Sharing the key name and secret To allow authentication the client and server has to share a secret. Usually the server dices a secret and displays it alltogether with the key name and the authentication mechanism as a QR code. [Google Authenticator](https://en.wikipedia.org/wiki/Google_Authenticator) and some other applications and hardware items – like the [Yubikey](https://www.yubico.com/products/yubikey-hardware/) – do not follow the standard by expecting the secrets not as hexadecimal but as [Base32](https://en.wikipedia.org/wiki/Base32) encoded data. ##### TOTP (Time-based One-time Password Algorithm) ```{php} use ChromaX\OathServerSuite\SecretSharing\SharedSecretQrCodeProvider\SharedSecretQrCodeProvider; use ChromaX\OathServerSuite\SecretSharing\SharedSecretUrlEncoder\TotpBase32SharedSecretUrlEncoder; use ChromaX\QrCodeSuite\QrEncode\QrEncoder; // Initialize Oath URL encoder for TOTP (Time-based One-time Password Algorithm) $contentEncoder = new TotpBase32SharedSecretUrlEncoder(); // Setting the key name $keyName = 'My Username'; // Setting the issuer name $issuerName = 'Awesome Application'; // Setting a secret // Attention: This is just an example value // Use a random value of a proper length stored with your user credentials $sharedSecret = openssl_random_pseudo_bytes(30); // Getting the shared secret URL for usage wihtout QR code provision $sharedSecretUrl = $contentEncoder->encode($keyName, $sharedSecret); // Start QR code provision // Initialize the QR code provider with Oath URL encoder for TOTP $sharedSecretQrProvider = new SharedSecretQrCodeProvider(new TotpBase32SharedSecretUrlEncoder(), $keyName, $sharedSecret, $issuerName); // Configure the QR code renderer for your needs $sharedSecretQrProvider->getQrEncoder() ->setLevel(QrEncoder::QR_CODE_LEVEL_LOW) ->setTempDir('/path/to/a/writable/temp-dir'); // Persist the QR code PNG to the filesystem $sharedSecretQrProvider->provideQrCode('/path/to/the/qrcode.png');
HOTP (HMAC-based One-time Password Algorithm)

```{php} use ChromaX\OathServerSuite\SecretSharing\SharedSecretQrCodeProvider\SharedSecretQrCodeProvider; use ChromaX\OathServerSuite\SecretSharing\SharedSecretUrlEncoder\HotpBase32SharedSecretUrlEncoder; use ChromaX\QrCodeSuite\QrEncode\QrEncoder;, (*12)

// Initialize Oath URL encoder for HOTP (HMAC-based One-time Password Algorithm) $contentEncoder = new HotpBase32SharedSecretUrlEncoder();, (*13)

// Setting the key name $keyName = 'My Username';, (*14)

// Setting the issuer name $issuerName = 'Awesome Application';, (*15)

// Setting a secret // Attention: This is just an example value // Use a random value of a proper length stored with your user credentials $sharedSecret = openssl_random_pseudo_bytes(30);, (*16)

// Getting the shared secret URL for usage wihtout QR code provision $sharedSecretUrl = $contentEncoder->encode($keyName, $sharedSecret);, (*17)

// Start QR code provision // Initialize the QR code provider with Oath URL encoder for HOTP $sharedSecretQrProvider = new SharedSecretQrCodeProvider(new HotpBase32SharedSecretUrlEncoder(), $keyName, $sharedSecret, $issuerName);, (*18)

// Configure the QR code renderer for your needs $sharedSecretQrProvider->getQrEncoder() ->setLevel(QrEncoder::QR_CODE_LEVEL_LOW) ->setTempDir('/path/to/a/writable/temp-dir');, (*19)

// Persist the QR code PNG to the filesystem $sharedSecretQrProvider->provideQrCode('/path/to/the/qrcode.png');, (*20)


#### Validating a Oath one time password ##### TOTP (Time-based One-time Password Algorithm) ```{php} $totp = $_POST['totp']; $sharedSecret = 'fetchedFromDatabaseOrSimilar'; $validator = new OathServerSuite\Validation\Oath\TotpValidator(); $validator->validate($totp, $sharedSecret); if ($validator->isValid()) { // Validation was successful } else { // Validation failed }
HOTP (HMAC-based One-time Password Algorithm)

```{php} $hotp = $_POST['hotp']; $sharedSecret = 'fetchedFromDatabaseOrSimilar'; $counter = (int)'fetchedFromDatabaseOrSimilar';, (*21)

$validator = new OathServerSuite\Validation\Oath\HotpValidator(); $validator->validate($hotp, $sharedSecret, $counter); if ($validator->isValid()) { // Validation was successful } else { // Validation failed }, (*22)


--- ### Oath – following the standard #### Sharing the key name and secret ##### TOTP (Time-based One-time Password Algorithm) ```{php} use ChromaX\OathServerSuite\SecretSharing\SharedSecretQrCodeProvider\SharedSecretQrCodeProvider; use ChromaX\OathServerSuite\SecretSharing\SharedSecretUrlEncoder\TotpSharedSecretUrlEncoder; use ChromaX\QrCodeSuite\QrEncode\QrEncoder; // Initialize Oath URL encoder for TOTP (Time-based One-time Password Algorithm) $contentEncoder = new TotpSharedSecretUrlEncoder(); // Setting the key name $keyName = 'My Username'; // Setting the issuer name $issuerName = 'Awesome Application'; // Setting a secret // Attention: This is just an example value // Use a random value of a proper length stored with your user credentials $sharedSecret = openssl_random_pseudo_bytes(30); // Getting the shared secret URL for usage wihtout QR code provision $sharedSecretUrl = $contentEncoder->encode($keyName, $sharedSecret); // Start QR code provision // Initialize the QR code provider with Oath URL encoder for TOTP $sharedSecretQrProvider = new SharedSecretQrCodeProvider(new TotpSharedSecretUrlEncoder(), $keyName, $sharedSecret, $issuerName); // Configure the QR code renderer for your needs $sharedSecretQrProvider->getQrEncoder() ->setLevel(QrEncoder::QR_CODE_LEVEL_LOW) ->setTempDir('/path/to/a/writable/temp-dir'); // Persist the QR code PNG to the filesystem $sharedSecretQrProvider->provideQrCode('/path/to/the/qrcode.png');
HOTP (HMAC-based One-time Password Algorithm)

```{php} use ChromaX\OathServerSuite\SecretSharing\SharedSecretQrCodeProvider\SharedSecretQrCodeProvider; use ChromaX\OathServerSuite\SecretSharing\SharedSecretUrlEncoder\HotpSharedSecretUrlEncoder; use ChromaX\QrCodeSuite\QrEncode\QrEncoder;, (*23)

// Initialize Oath URL encoder for HOTP (HMAC-based One-time Password Algorithm) $contentEncoder = new HotpSharedSecretUrlEncoder();, (*24)

// Setting the key name $keyName = 'My Username';, (*25)

// Setting the issuer name $issuerName = 'Awesome Application';, (*26)

// Setting a secret // Attention: This is just an example value // Use a random value of a proper length stored with your user credentials $sharedSecret = openssl_random_pseudo_bytes(30);, (*27)

// Getting the shared secret URL for usage wihtout QR code provision $sharedSecretUrl = $contentEncoder->encode($keyName, $sharedSecret);, (*28)

// Start QR code provision // Initialize the QR code provider with Oath URL encoder for HOTP $sharedSecretQrProvider = new SharedSecretQrCodeProvider(new HotpSharedSecretUrlEncoder(), $keyName, $sharedSecret, $issuerName);, (*29)

// Configure the QR code renderer for your needs $sharedSecretQrProvider->getQrEncoder() ->setLevel(QrEncoder::QR_CODE_LEVEL_LOW) ->setTempDir('/path/to/a/writable/temp-dir');, (*30)

// Persist the QR code PNG to the filesystem $sharedSecretQrProvider->provideQrCode('/path/to/the/qrcode.png');, (*31)


#### Validating a Oath one time password ##### TOTP (Time-based One-time Password Algorithm) ```{php} $totp = $_POST['totp']; $sharedSecret = 'fetchedFromDatabaseOrSimilar'; $validator = new OathServerSuite\Validation\Oath\TotpValidator(); $validator->validate($totp, $sharedSecret); if ($validator->isValid()) { // Validation was successful } else { // Validation failed }
HOTP (HMAC-based One-time Password Algorithm)

```{php} $hotp = $_POST['hotp']; $sharedSecret = 'fetchedFromDatabaseOrSimilar'; $counter = (int)'fetchedFromDatabaseOrSimilar';, (*32)

$validator = new OathServerSuite\Validation\Oath\HotpValidator(); $validator->validate($hotp, $sharedSecret, $counter); if ($validator->isValid()) { // Validation was successful } else { // Validation failed } ```, (*33)


Exception handling

PHP Oath Server Suite provides different exceptions – some provided by the PHP Common Exceptions project – for proper handling.
You can find more information about PHP Common Exceptions at Github., (*34)


Contribution

Contributing to our projects is always very appreciated.
But: please follow the contribution guidelines written down in the CONTRIBUTING.md document., (*35)

License

PHP Oath Server Suite is under the MIT license., (*36)

The Versions

06/02 2017

dev-master

9999999-dev http://markenwerk.net/

A collection of classes to provide second factor authentication like Yubico OTP (Yubikey), Oath (TOTP, HOTP, GoogleAuthenticator) server-side.

  Sources   Download

MIT

The Requires

 

The Development Requires

otp google authenticator oath totp yubico hotp second factor authentication

06/02 2017

4.0.4

4.0.4.0 http://markenwerk.net/

A collection of classes to provide second factor authentication like Yubico OTP (Yubikey), Oath (TOTP, HOTP, GoogleAuthenticator) server-side.

  Sources   Download

MIT

The Requires

 

The Development Requires

otp google authenticator oath totp yubico hotp second factor authentication

01/02 2017

4.0.3

4.0.3.0 http://markenwerk.net/

A collection of classes to provide second factor authentication like Yubico OTP (Yubikey), Oath (TOTP, HOTP, GoogleAuthenticator) server-side.

  Sources   Download

MIT

The Requires

 

The Development Requires

otp google authenticator oath totp yubico hotp second factor authentication

01/02 2017

4.0.2

4.0.2.0 http://markenwerk.net/

A collection of classes to provide second factor authentication like Yubico OTP (Yubikey), Oath (TOTP, HOTP, GoogleAuthenticator) server-side.

  Sources   Download

MIT

The Requires

 

The Development Requires

otp google authenticator oath totp yubico hotp second factor authentication

15/07 2016

4.0.1

4.0.1.0 http://markenwerk.net/

A collection of classes to provide second factor authentication like Yubico OTP (Yubikey), Oath (TOTP, HOTP, GoogleAuthenticator) server-side.

  Sources   Download

MIT

The Requires

 

The Development Requires

otp google authenticator oath totp yubico hotp second factor authentication

11/07 2016

4.0.0

4.0.0.0 http://markenwerk.net/

A collection of classes to provide second factor authentication like Yubico OTP (Yubikey), Oath (TOTP, HOTP, GoogleAuthenticator) server-side.

  Sources   Download

MIT

The Requires

 

The Development Requires

otp google authenticator oath totp yubico hotp second factor authentication

26/04 2016

3.0.13

3.0.13.0 http://markenwerk.net/

A collection of classes to provide second factor authentication like Yubico OTP (Yubikey), Oath (TOTP, HOTP, GoogleAuthenticator) server-side.

  Sources   Download

MIT

The Requires

 

The Development Requires

otp google authenticator oath totp yubico hotp second factor authentication

18/04 2016

3.0.12

3.0.12.0 http://markenwerk.net/

A collection of classes to provide second factor authentication like Yubico OTP (Yubikey), Oath (TOTP, HOTP, GoogleAuthenticator) server-side.

  Sources   Download

MIT

The Requires

 

The Development Requires

otp google authenticator oath totp yubico hotp second factor authentication

15/04 2016

3.0.11

3.0.11.0 http://markenwerk.net/

A collection of classes to provide second factor authentication like Yubico OTP (Yubikey), Oath (TOTP, HOTP, GoogleAuthenticator) server-side.

  Sources   Download

MIT

The Requires

 

The Development Requires

otp google authenticator oath totp yubico hotp second factor authentication

15/04 2016

3.0.10

3.0.10.0 http://markenwerk.net/

A collection of classes to provide second factor authentication like Yubico OTP (Yubikey), Oath (TOTP, HOTP, GoogleAuthenticator) server-side.

  Sources   Download

MIT

The Requires

 

The Development Requires

otp google authenticator oath totp yubico hotp second factor authentication

15/04 2016

3.0.9

3.0.9.0 http://markenwerk.net/

A collection of classes to provide second factor authentication like Yubico OTP (Yubikey), Oath (TOTP, HOTP, GoogleAuthenticator) server-side.

  Sources   Download

MIT

The Requires

 

The Development Requires

otp google authenticator oath totp yubico hotp second factor authentication

13/04 2016

3.0.8

3.0.8.0 http://markenwerk.net/

A collection of classes to provide second factor authentication like Yubico OTP (Yubikey), Oath (TOTP, HOTP, GoogleAuthenticator) server-side.

  Sources   Download

MIT

The Requires

 

The Development Requires

otp google authenticator oath totp yubico hotp second factor authentication

13/04 2016

3.0.7

3.0.7.0 http://markenwerk.net/

A collection of classes to provide second factor authentication (Yubico OTP, TOTP, HOTP, GoogleAuthenticator) server-side.

  Sources   Download

MIT

The Requires

 

The Development Requires

otp google authenticator oath totp yubico hotp second factor authentication

13/04 2016

3.0.6

3.0.6.0 http://markenwerk.net/

A collection of classes to provide second factor authentication (Yubico OTP, TOTP, HOTP, GoogleAuthenticator) server-side.

  Sources   Download

MIT

The Requires

 

The Development Requires

otp google authenticator oath totp yubico hotp second factor authentication

13/04 2016

3.0.5

3.0.5.0 http://markenwerk.net/

A collection of classes to provide second factor authentication (Yubico OTP, TOTP, HOTP, GoogleAuthenticator) server-side.

  Sources   Download

MIT

The Requires

 

The Development Requires

otp google authenticator oath totp yubico hotp second factor authentication

13/04 2016

3.0.4

3.0.4.0 http://markenwerk.net/

A collection of classes to provide second factor authentication (Yubico OTP, TOTP, HOTP, GoogleAuthenticator) server-side.

  Sources   Download

MIT

The Requires

 

The Development Requires

otp google authenticator oath totp yubico hotp second factor authentication

13/04 2016

3.0.3

3.0.3.0 http://markenwerk.net/

A collection of classes to provide second factor authentication (Yubico OTP, TOTP, HOTP, GoogleAuthenticator) server-side.

  Sources   Download

MIT

The Requires

 

The Development Requires

otp google authenticator oath totp yubico hotp second factor authentication

13/04 2016

3.0.2

3.0.2.0 http://markenwerk.net/

A collection of classes to provide second factor authentication (Yubico OTP, TOTP, HOTP, GoogleAuthenticator) server-side.

  Sources   Download

MIT

The Requires

 

The Development Requires

otp google authenticator oath totp yubico hotp second factor authentication

13/04 2016

3.0.1

3.0.1.0 http://markenwerk.net/

A collection of classes to provide second factor authentication (Yubico OTP, TOTP, HOTP, GoogleAuthenticator) server-side.

  Sources   Download

MIT

The Requires

 

The Development Requires

otp google authenticator oath totp yubico hotp second factor authentication

13/04 2016

3.0

3.0.0.0 http://markenwerk.net/

A collection of classes to provide second factor authentication (Yubico OTP, TOTP, HOTP, GoogleAuthenticator) server-side.

  Sources   Download

MIT

The Requires

 

The Development Requires

otp google authenticator oath totp yubico hotp second factor authentication

13/04 2016

2.0

2.0.0.0 http://markenwerk.net/

A collection of classes to provide second factor authentication (Yubico OTP, TOTP, HOTP, GoogleAuthenticator) server-side.

  Sources   Download

MIT

The Requires

 

The Development Requires

otp google authenticator oath totp yubico hotp second factor authentication

12/04 2016

1.1

1.1.0.0 http://markenwerk.net/

A collection of classes to provide second factor authentication (Yubico OTP, TOTP, HOTP, GoogleAuthenticator) server-side.

  Sources   Download

MIT

The Requires

 

The Development Requires

otp google authenticator oath totp yubico hotp second factor authentication

12/04 2016

1.0

1.0.0.0 http://markenwerk.net/

A collection of classes to provide second factor authentication (Yubico OTP, TOTP, HOTP, GoogleAuthenticator) server-side.

  Sources   Download

MIT

The Requires

 

The Development Requires

otp google authenticator oath totp yubico hotp second factor authentication