mirror of
https://github.com/chillerlan/php-qrcode.git
synced 2026-08-30 20:17:17 +00:00
✨ QRAuthenticator trait
This commit is contained in:
+4
-4
@@ -19,14 +19,13 @@
|
||||
],
|
||||
"require": {
|
||||
"php": ">=7.0.3",
|
||||
"chillerlan/php-traits": "1.1.*"
|
||||
"chillerlan/php-traits": "1.1.*",
|
||||
"chillerlan/php-authenticator": ">=2.0.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"chillerlan/php-googleauth": "1.1.*",
|
||||
"phpunit/phpunit": "6.5.*"
|
||||
},
|
||||
"suggest": {
|
||||
"chillerlan/php-googleauth": "*"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
@@ -36,7 +35,8 @@
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"chillerlan\\QRCodePublic\\": "public/",
|
||||
"chillerlan\\QRCodeTest\\": "tests/"
|
||||
"chillerlan\\QRCodeTest\\": "tests/",
|
||||
"chillerlan\\QRCodeExamples\\": "examples/"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
/**
|
||||
* Trait QRAuthenticator
|
||||
*
|
||||
* @filesource QRAuthenticator.php
|
||||
* @created 21.12.2017
|
||||
* @package chillerlan\QRCode\Traits
|
||||
* @author Smiley <smiley@chillerlan.net>
|
||||
* @copyright 2017 Smiley
|
||||
* @license MIT
|
||||
*/
|
||||
|
||||
namespace chillerlan\QRCode\Traits;
|
||||
|
||||
use chillerlan\Authenticator\Authenticator;
|
||||
use chillerlan\QRCode\QRCode;
|
||||
|
||||
/**
|
||||
* Creates URI QR Codes for use with mmobile authenticators
|
||||
*/
|
||||
trait QRAuthenticator{
|
||||
|
||||
/**
|
||||
* @var \chillerlan\QRCode\QROptions
|
||||
*/
|
||||
protected $qrOptions;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $authenticatorSecret;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $authenticatorDigits = Authenticator::DEFAULT_DIGITS;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $authenticatorPeriod = Authenticator::DEFAULT_PERIOD;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $authenticatorMode = Authenticator::DEFAULT_AUTH_MODE;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $authenticatorAlgo = Authenticator::DEFAULT_HASH_ALGO;
|
||||
|
||||
/**
|
||||
* @param string $label
|
||||
* @param string $issuer
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getURIQRCode(string $label, string $issuer) {
|
||||
$uri = $this->getAuthenticator()->setSecret($this->authenticatorSecret)->getUri($label, $issuer);
|
||||
|
||||
return (new QRCode($this->qrOptions))->render($uri);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \chillerlan\Authenticator\Authenticator
|
||||
*/
|
||||
protected function getAuthenticator():Authenticator {
|
||||
return (new Authenticator)
|
||||
->setPeriod($this->authenticatorPeriod)
|
||||
->setDigits($this->authenticatorDigits)
|
||||
->setMode($this->authenticatorMode)
|
||||
->setAlgorithm($this->authenticatorAlgo)
|
||||
;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user