Update website
This commit is contained in:
parent
bb4b0f9be8
commit
011b183e28
4263 changed files with 3014 additions and 720369 deletions
|
@ -1,26 +0,0 @@
|
|||
## Change Log
|
||||
|
||||
## [2.0.1] - 2020-10-17
|
||||
### Removed
|
||||
- Support for Bacon QRCode 1.x
|
||||
|
||||
## [2.0.0] - 2020-10-16
|
||||
### Changed
|
||||
- Add support for SVG QRCodes
|
||||
- No need to install the Imagick extension
|
||||
- Allow users to define their on QRCode service renderer
|
||||
- Breaking change: beginning on version 2.0 the rendering service is optional, so you have to manually install one of those packages in order to generate QRCodes: [BaconQrCode](https://github.com/Bacon/BaconQrCode): renders PNG by default, but requires the Imagick PHP extension. [chillerlan/php-qrcode](https://github.com/chillerlan/php-qrcode): renders SVG by default and don't require the Imagick PHP extension.
|
||||
- Add PHP 8.0 compatibility
|
||||
|
||||
## [1.0.2] - 2018-10-10
|
||||
### Changed
|
||||
- Dropped support for PHP 5.4 & PHP 5.5
|
||||
- Test QRCode by decoding it
|
||||
|
||||
## [1.0.1] - 2018-10-10
|
||||
### Added
|
||||
- Add support for more image renderer back ends
|
||||
|
||||
## [1.0.0] - 2018-10-06
|
||||
### Added
|
||||
- Package created
|
|
@ -1,7 +0,0 @@
|
|||
Copyright 2014-2018 Phil, Antonio Carlos Ribeiro and All Contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@ -1,149 +0,0 @@
|
|||
# Google2FA QRCode
|
||||
|
||||
<p align="center">
|
||||
<a href="https://packagist.org/packages/pragmarx/google2fa-qrcode"><img alt="Latest Stable Version" src="https://img.shields.io/packagist/v/pragmarx/google2fa-qrcode.svg?style=flat-square"></a>
|
||||
<a href="LICENSE.md"><img alt="License" src="https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square"></a>
|
||||
<a href="https://scrutinizer-ci.com/g/antonioribeiro/google2fa/?branch=master"><img alt="Code Quality" src="https://img.shields.io/scrutinizer/g/antonioribeiro/google2fa.svg?style=flat-square"></a>
|
||||
<a href="https://travis-ci.org/antonioribeiro/google2fa"><img alt="Build" src="https://img.shields.io/travis/antonioribeiro/google2fa.svg?style=flat-square"></a>
|
||||
</p>
|
||||
<p align="center">
|
||||
<a href="https://packagist.org/packages/pragmarx/google2fa-qrcode"><img alt="Downloads" src="https://img.shields.io/packagist/dt/pragmarx/google2fa-qrcode.svg?style=flat-square"></a>
|
||||
<a href="https://scrutinizer-ci.com/g/antonioribeiro/google2fa/?branch=master"><img alt="Coverage" src="https://img.shields.io/scrutinizer/coverage/g/antonioribeiro/google2fa.svg?style=flat-square"></a>
|
||||
<a href="https://styleci.io/repos/24296182"><img alt="StyleCI" src="https://styleci.io/repos/24296182/shield"></a>
|
||||
<a href="https://travis-ci.org/antonioribeiro/google2fa"><img alt="PHP" src="https://img.shields.io/badge/PHP-5.4%20--%207.3-brightgreen.svg?style=flat-square"></a>
|
||||
</p>
|
||||
|
||||
### QRCode For Google2FA
|
||||
|
||||
This is package is [Goole2FA](https://github.com/antonioribeiro/google2fa) integrated with a QRCode generator, providing an easy way to plot QRCode for your two factor authentication. For documentation related to Google2FA, please check the [documentation of the main package](https://github.com/antonioribeiro/google2fa).
|
||||
|
||||
## Requirements
|
||||
|
||||
- PHP 5.4+
|
||||
|
||||
## Installing
|
||||
|
||||
Use Composer to install it:
|
||||
|
||||
```
|
||||
composer require pragmarx/google2fa-qrcode
|
||||
```
|
||||
|
||||
## Using It
|
||||
|
||||
### Instantiate it directly
|
||||
|
||||
```php
|
||||
use PragmaRX\Google2FAQRCode\Google2FA;
|
||||
|
||||
$google2fa = new Google2FA();
|
||||
|
||||
return $google2fa->generateSecretKey();
|
||||
```
|
||||
|
||||
## Generating QRCodes
|
||||
|
||||
The securer way of creating QRCode is to do it yourself or using a library. First you have to install the BaconQrCode package, as stated above, then you just have to generate the inline string using:
|
||||
|
||||
```php
|
||||
$inlineUrl = $google2fa->getQRCodeInline(
|
||||
$companyName,
|
||||
$companyEmail,
|
||||
$secretKey
|
||||
);
|
||||
```
|
||||
|
||||
And use it in your blade template this way:
|
||||
|
||||
```html
|
||||
<img src="{{ $inlineUrl }}">
|
||||
```
|
||||
|
||||
```php
|
||||
$secretKey = $google2fa->generateSecretKey(16, $userId);
|
||||
```
|
||||
|
||||
## Show the QR Code to your user, via Google Apis
|
||||
|
||||
It's insecure to use it via Google Apis, so you have to enable it before using it.
|
||||
|
||||
```php
|
||||
$google2fa->setAllowInsecureCallToGoogleApis(true);
|
||||
|
||||
$google2fa_url = $google2fa->getQRCodeGoogleUrl(
|
||||
'YourCompany',
|
||||
$user->email,
|
||||
$user->google2fa_secret
|
||||
);
|
||||
|
||||
/// and in your view:
|
||||
|
||||
<img src="{{ $google2fa_url }}" alt="">
|
||||
```
|
||||
|
||||
And they should see and scan the QR code to their applications:
|
||||
|
||||

|
||||
|
||||
And to verify, you just have to:
|
||||
|
||||
```php
|
||||
$secret = $request->input('secret');
|
||||
|
||||
$valid = $google2fa->verifyKey($user->google2fa_secret, $secret);
|
||||
```
|
||||
|
||||
## Replacing the QRCode rendering service
|
||||
|
||||
If you want to use a different service, you just have to
|
||||
|
||||
```php
|
||||
$google2fa->setQrcodeService(new YourService())
|
||||
->getQRCodeInline(
|
||||
$companyName,
|
||||
$companyEmail,
|
||||
$secretKey
|
||||
);
|
||||
```
|
||||
|
||||
## Built-in QRCode rendering services
|
||||
|
||||
Beginning on version 2.0 the rendering service is optional, so you have to manually install one of those packages in order to generate QRCodes:
|
||||
|
||||
- [BaconQrCode](https://github.com/Bacon/BaconQrCode): renders PNG by default, but requires the Imagick PHP extension. You can configure it to use different backends, but you'll have to instantiate it yourself.
|
||||
- [chillerlan/php-qrcode](https://github.com/chillerlan/php-qrcode): renders SVG by default and don't require the Imagick PHP extension, but can also generate other formats, which may require Imagick.
|
||||
|
||||
## Using a diffent image backend
|
||||
|
||||
```php
|
||||
$google2fa->setQrcodeService(
|
||||
new \PragmaRX\Google2FAQRCode\QRCode\Bacon(
|
||||
new \BaconQrCode\Renderer\Image\SvgImageBackEnd()
|
||||
)
|
||||
);
|
||||
|
||||
// or
|
||||
|
||||
$google2fa = new Google2FA(
|
||||
new Bacon(
|
||||
new \BaconQrCode\Renderer\Image\SvgImageBackEnd()
|
||||
)
|
||||
);
|
||||
```
|
||||
|
||||
## Tests
|
||||
|
||||
The package tests were written with [PHPUnit](https://phpunit.de/).
|
||||
|
||||
## Authors
|
||||
|
||||
- [Antonio Carlos Ribeiro](http://twitter.com/iantonioribeiro)
|
||||
- [All Contributors](https://github.com/antonioribeiro/google2fa/graphs/contributors)
|
||||
|
||||
## License
|
||||
|
||||
Google2FAQRCode is licensed under the MIT License - see the [LICENSE](LICENSE.md) file for details.
|
||||
|
||||
## Contributing
|
||||
|
||||
Pull requests and issues are more than welcome.
|
|
@ -1,41 +0,0 @@
|
|||
{
|
||||
"name": "pragmarx/google2fa-qrcode",
|
||||
"description": "QR Code package for Google2FA",
|
||||
"keywords": ["authentication", "two factor authentication", "google2fa", "2fa", "QRCode", "qr code"],
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Antonio Carlos Ribeiro",
|
||||
"email": "acr@antoniocarlosribeiro.com",
|
||||
"role": "Creator & Designer"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=7.1",
|
||||
"pragmarx/google2fa": ">=4.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "~4|~5|~6|~7|~8|~9",
|
||||
"khanamiryan/qrcode-detector-decoder": "^1.0",
|
||||
"bacon/bacon-qr-code": "^2.0",
|
||||
"chillerlan/php-qrcode": "^1.0|^2.0|^3.0|^4.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"PragmaRX\\Google2FAQRCode\\": "src/",
|
||||
"PragmaRX\\Google2FAQRCode\\Tests\\": "tests/"
|
||||
}
|
||||
},
|
||||
"suggest": {
|
||||
"bacon/bacon-qr-code": "For QR Code generation, requires imagick",
|
||||
"chillerlan/php-qrcode": "For QR Code generation"
|
||||
},
|
||||
"extra": {
|
||||
"component": "package",
|
||||
"branch-alias": {
|
||||
"dev-master": "1.0-dev"
|
||||
}
|
||||
},
|
||||
"minimum-stability": "dev",
|
||||
"prefer-stable": true
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace PragmaRX\Google2FAQRCode\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
class MissingQrCodeServiceException extends Exception
|
||||
{
|
||||
}
|
|
@ -1,112 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace PragmaRX\Google2FAQRCode;
|
||||
|
||||
use BaconQrCode\Writer;
|
||||
use BaconQrCode\Renderer\Image\Png;
|
||||
use BaconQrCode\Renderer\ImageRenderer;
|
||||
use PragmaRX\Google2FAQRCode\QRCode\Bacon;
|
||||
use PragmaRX\Google2FAQRCode\QRCode\Chillerlan;
|
||||
use BaconQrCode\Renderer\Image\RendererInterface;
|
||||
use BaconQrCode\Writer as BaconQrCodeWriter;
|
||||
use BaconQrCode\Renderer\Image\ImagickImageBackEnd;
|
||||
use PragmaRX\Google2FA\Google2FA as Google2FAPackage;
|
||||
use BaconQrCode\Renderer\RendererStyle\RendererStyle;
|
||||
use BaconQrCode\Renderer\Image\ImageBackEndInterface;
|
||||
use PragmaRX\Google2FAQRCode\Exceptions\MissingQrCodeServiceException;
|
||||
|
||||
class Google2FA extends Google2FAPackage
|
||||
{
|
||||
/**
|
||||
* @var ImageBackEndInterface|RendererInterface|null $imageBackEnd
|
||||
*/
|
||||
protected $qrCodeService;
|
||||
|
||||
/**
|
||||
* Google2FA constructor.
|
||||
*
|
||||
* @param ImageBackEndInterface|RendererInterface|null $imageBackEnd
|
||||
*/
|
||||
public function __construct($qrCodeService = null)
|
||||
{
|
||||
$this->setQrCodeService(
|
||||
empty($qrCodeService)
|
||||
? $this->qrCodeServiceFactory()
|
||||
: $qrCodeService
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a QR code data url to display inline.
|
||||
*
|
||||
* @param string $company
|
||||
* @param string $holder
|
||||
* @param string $secret
|
||||
* @param int $size
|
||||
* @param string $encoding Default to UTF-8
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getQRCodeInline(
|
||||
$company,
|
||||
$holder,
|
||||
$secret,
|
||||
$size = 200,
|
||||
$encoding = 'utf-8'
|
||||
) {
|
||||
if (empty($this->getQrCodeService())) {
|
||||
throw new MissingQrCodeServiceException(
|
||||
'You need to install a service package or assign yourself the service to be used.'
|
||||
);
|
||||
}
|
||||
|
||||
return $this->qrCodeService->getQRCodeInline(
|
||||
$this->getQRCodeUrl($company, $holder, $secret),
|
||||
$size,
|
||||
$encoding
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Service setter
|
||||
*
|
||||
* @return \PragmaRX\Google2FAQRCode\QRCode\QRCodeServiceContract
|
||||
*/
|
||||
public function getQrCodeService()
|
||||
{
|
||||
return $this->qrCodeService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Service setter
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setQrCodeService($service)
|
||||
{
|
||||
$this->qrCodeService = $service;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the QR Code service instance
|
||||
*
|
||||
* @return \PragmaRX\Google2FAQRCode\QRCode\QRCodeServiceContract
|
||||
*/
|
||||
public function qrCodeServiceFactory()
|
||||
{
|
||||
if (
|
||||
class_exists('BaconQrCode\Writer') &&
|
||||
class_exists('BaconQrCode\Renderer\ImageRenderer')
|
||||
) {
|
||||
return new Bacon();
|
||||
}
|
||||
|
||||
if (class_exists('chillerlan\QRCode\QRCode')) {
|
||||
return new Chillerlan();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -1,97 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace PragmaRX\Google2FAQRCode\QRCode;
|
||||
|
||||
use BaconQrCode\Renderer\ImageRenderer;
|
||||
use BaconQrCode\Writer as BaconQrCodeWriter;
|
||||
use BaconQrCode\Renderer\Image\SvgImageBackEnd;
|
||||
use BaconQrCode\Renderer\Image\ImageBackEndInterface;
|
||||
use BaconQrCode\Renderer\Image\ImagickImageBackEnd;
|
||||
use BaconQrCode\Renderer\RendererStyle\RendererStyle;
|
||||
use BaconQrCode\Writer;
|
||||
|
||||
class Bacon implements QRCodeServiceContract
|
||||
{
|
||||
/**
|
||||
* @var ImageBackEndInterface|RendererInterface|null $imageBackEnd
|
||||
*/
|
||||
protected $imageBackEnd;
|
||||
|
||||
/**
|
||||
* Google2FA constructor.
|
||||
*
|
||||
* @param ImageBackEndInterface|RendererInterface|null $imageBackEnd
|
||||
*/
|
||||
public function __construct($imageBackEnd = null)
|
||||
{
|
||||
$this->imageBackEnd = $imageBackEnd;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a QR code data url to display inline.
|
||||
*
|
||||
* @param string $string
|
||||
* @param int $size
|
||||
* @param string $encoding Default to UTF-8
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getQRCodeInline($string, $size = 200, $encoding = 'utf-8')
|
||||
{
|
||||
$renderer = new ImageRenderer(
|
||||
(new RendererStyle($size))->withSize($size),
|
||||
$this->getImageBackEnd()
|
||||
);
|
||||
|
||||
$bacon = new Writer($renderer);
|
||||
|
||||
$data = $bacon->writeString($string, $encoding);
|
||||
|
||||
if ($this->getImageBackEnd() instanceof ImagickImageBackEnd) {
|
||||
return 'data:image/png;base64,' . base64_encode($data);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if Imagick is available
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function imagickIsAvailable()
|
||||
{
|
||||
return extension_loaded('imagick');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get image backend
|
||||
*
|
||||
* @return ImageRenderer
|
||||
*/
|
||||
public function getImageBackend()
|
||||
{
|
||||
if (empty($this->imageBackEnd)) {
|
||||
$this->imageBackEnd = !$this->imagickIsAvailable()
|
||||
? new SvgImageBackEnd()
|
||||
: new ImagickImageBackEnd();
|
||||
}
|
||||
|
||||
$this->setImageBackEnd($this->imageBackEnd);
|
||||
|
||||
return $this->imageBackEnd;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set image backend
|
||||
*
|
||||
* @param $imageBackEnd
|
||||
* @return $this
|
||||
*/
|
||||
public function setImageBackend($imageBackEnd)
|
||||
{
|
||||
$this->imageBackEnd = $imageBackEnd;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
|
@ -1,80 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace PragmaRX\Google2FAQRCode\QRCode;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use chillerlan\QRCode\QRCode;
|
||||
use chillerlan\QRCode\QROptions;
|
||||
use BaconQrCode\Writer as BaconQrCodeWriter;
|
||||
|
||||
class Chillerlan implements QRCodeServiceContract
|
||||
{
|
||||
protected $options = [];
|
||||
|
||||
/**
|
||||
* Get QRCode options.
|
||||
*
|
||||
* @param int $size
|
||||
* @return \chillerlan\QRCode\QROptions
|
||||
*/
|
||||
protected function getOptions()
|
||||
{
|
||||
$options = new QROptions($this->buildOptionsArray());
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set QRCode options.
|
||||
*
|
||||
* @param array $options
|
||||
* @return self
|
||||
*/
|
||||
protected function setOptions($options)
|
||||
{
|
||||
$this->options = $options;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the options array
|
||||
*
|
||||
* @param null $size
|
||||
* @return array
|
||||
*/
|
||||
public function buildOptionsArray($size = null)
|
||||
{
|
||||
$defaults = [
|
||||
'version' => QRCode::VERSION_AUTO,
|
||||
'outputType' => QRCode::OUTPUT_MARKUP_SVG,
|
||||
'eccLevel' => QRCode::ECC_L,
|
||||
];
|
||||
|
||||
return array_merge($defaults, $this->options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a QR code data url to display inline.
|
||||
*
|
||||
* @param string $string
|
||||
* @param int $size
|
||||
* @param string $encoding Default to UTF-8
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getQRCodeInline($string, $size = null, $encoding = null)
|
||||
{
|
||||
$renderer = new QRCode($this->getOptions());
|
||||
|
||||
$header = "data:image/svg+xml;base64,";
|
||||
|
||||
$image = $renderer->render($string);
|
||||
|
||||
if (strncmp($image, $header, strlen($header)) === 0) {
|
||||
return $image;
|
||||
}
|
||||
|
||||
return $header . base64_encode($image);
|
||||
}
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace PragmaRX\Google2FAQRCode\QRCode;
|
||||
|
||||
interface QRCodeServiceContract
|
||||
{
|
||||
/**
|
||||
* Generates a QR code data url to display inline.
|
||||
*
|
||||
* @param string $string
|
||||
* @param int $size
|
||||
* @param string $encoding Default to UTF-8
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getQRCodeInline($string, $size = 200, $encoding = 'utf-8');
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue