mirror of
https://github.com/RobThree/TwoFactorAuth.git
synced 2026-08-25 16:06:33 +00:00
Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 85408c4e77 | |||
| 3516aae5a3 | |||
| a2fa4c11a9 | |||
| 57970d3d5f | |||
| 83918a7658 | |||
| 9b2d795acc | |||
| 24f6d2fd10 | |||
| 6d70f9ca8e | |||
| 92487acba4 | |||
| ab4c33007f | |||
| 0ab012bbaf |
@@ -10,11 +10,16 @@ jobs:
|
|||||||
|
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
php-version: ['8.2', '8.3']
|
php-version: [8.2, 8.3, 8.4, 8.5]
|
||||||
bacon-version: ['^2', '^3']
|
bacon-version: ["^2", "^3"]
|
||||||
|
exclude:
|
||||||
|
- php-version: 8.4
|
||||||
|
bacon-version: "^2"
|
||||||
|
- php-version: 8.5
|
||||||
|
bacon-version: "^2"
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v5
|
||||||
|
|
||||||
- uses: shivammathur/setup-php@v2
|
- uses: shivammathur/setup-php@v2
|
||||||
with:
|
with:
|
||||||
|
|||||||
@@ -10,11 +10,24 @@ jobs:
|
|||||||
|
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
php-version: ['8.2', '8.3']
|
php-version: [8.2, 8.3, 8.4, 8.5]
|
||||||
endroid-version: ["^3","^4","^5"]
|
endroid-version: ["^3", "^4", "^5", "^6"]
|
||||||
|
exclude:
|
||||||
|
- php-version: 8.4
|
||||||
|
endroid-version: "^3"
|
||||||
|
- php-version: 8.4
|
||||||
|
endroid-version: "^4"
|
||||||
|
- php-version: 8.4
|
||||||
|
endroid-version: "^5"
|
||||||
|
- php-version: 8.5
|
||||||
|
endroid-version: "^3"
|
||||||
|
- php-version: 8.5
|
||||||
|
endroid-version: "^4"
|
||||||
|
- php-version: 8.5
|
||||||
|
endroid-version: "^5"
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v5
|
||||||
|
|
||||||
- uses: shivammathur/setup-php@v2
|
- uses: shivammathur/setup-php@v2
|
||||||
with:
|
with:
|
||||||
|
|||||||
@@ -10,10 +10,10 @@ jobs:
|
|||||||
|
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
php-version: ['8.2', '8.3']
|
php-version: [8.2, 8.3, 8.4, 8.5]
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v5
|
||||||
|
|
||||||
- uses: shivammathur/setup-php@v2
|
- uses: shivammathur/setup-php@v2
|
||||||
with:
|
with:
|
||||||
|
|||||||
@@ -8,23 +8,16 @@ PHP library for [two-factor (or multi-factor) authentication](http://en.wikipedi
|
|||||||
<img src="https://raw.githubusercontent.com/RobThree/TwoFactorAuth/master/multifactorauthforeveryone.png">
|
<img src="https://raw.githubusercontent.com/RobThree/TwoFactorAuth/master/multifactorauthforeveryone.png">
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
## Warning:
|
|
||||||
|
|
||||||
By default, this package uses the `lib/Providers/QRServerProvider.php` as QR code generator. This provider is __not__ suggested for applications where absolute security is needed, because it uses an external service for the QR code generation.
|
|
||||||
|
|
||||||
|
|
||||||
You can make use of the included [Endroid](https://robthree.github.io/TwoFactorAuth/qr-codes/endroid.html) or [Bacon](https://robthree.github.io/TwoFactorAuth/qr-codes/bacon.html) providers which generate locally.
|
|
||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
|
|
||||||
* Requires PHP version >=8.2
|
* Requires PHP version >=8.2
|
||||||
* [cURL](http://php.net/manual/en/book.curl.php) when using the provided `QRServerProvider` (default), `ImageChartsQRCodeProvider` or `QRicketProvider` but you can also provide your own QR-code provider.
|
|
||||||
|
|
||||||
Optionally, you may need:
|
Optionally, you may need:
|
||||||
|
|
||||||
* [sockets](https://www.php.net/manual/en/book.sockets.php) if you are using `NTPTimeProvider`
|
* [sockets](https://www.php.net/manual/en/book.sockets.php) if you are using `NTPTimeProvider`
|
||||||
* [endroid/qr-code](https://github.com/endroid/qr-code) if using `EndroidQrCodeProvider` or `EndroidQrCodeWithLogoProvider`.
|
* [endroid/qr-code](https://github.com/endroid/qr-code) if using `EndroidQrCodeProvider` or `EndroidQrCodeWithLogoProvider`.
|
||||||
* [bacon/bacon-qr-code](https://github.com/Bacon/BaconQrCode) if using `BaconQrCodeProvider`.
|
* [bacon/bacon-qr-code](https://github.com/Bacon/BaconQrCode) if using `BaconQrCodeProvider`.
|
||||||
|
* [php-curl library](http://php.net/manual/en/book.curl.php) when using an external QR Code provider such as `QRServerProvider`, `ImageChartsQRCodeProvider`, `QRicketProvider` or any other custom provider connecting to an external service.
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
@@ -40,7 +33,7 @@ If you need more in-depth information about the configuration available then you
|
|||||||
|
|
||||||
## Integrations
|
## Integrations
|
||||||
|
|
||||||
- [CakePHP 3](https://github.com/andrej-griniuk/cakephp-two-factor-auth)
|
- [CakePHP plugin](https://github.com/andrej-griniuk/cakephp-two-factor-auth)
|
||||||
- [CI4-Auth: a user, group, role and permission management library for Codeigniter 4](https://github.com/glewe/ci4-auth)
|
- [CI4-Auth: a user, group, role and permission management library for Codeigniter 4](https://github.com/glewe/ci4-auth)
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|||||||
+4
-2
@@ -11,8 +11,10 @@
|
|||||||
include_once str_replace(array('RobThree\\Auth', '\\'), array(__DIR__.'/../lib', '/'), $className) . '.php';
|
include_once str_replace(array('RobThree\\Auth', '\\'), array(__DIR__.'/../lib', '/'), $className) . '.php';
|
||||||
});
|
});
|
||||||
|
|
||||||
// substitute your company or app name here
|
$tfa = new RobThree\Auth\TwoFactorAuth(
|
||||||
$tfa = new RobThree\Auth\TwoFactorAuth(new RobThree\Auth\Providers\Qr\QRServerProvider());
|
new RobThree\Auth\Providers\Qr\QRServerProvider(),
|
||||||
|
"Acme Corp" // substitute your company or app name here
|
||||||
|
);
|
||||||
?>
|
?>
|
||||||
<li>First create a secret and associate it with a user</li>
|
<li>First create a secret and associate it with a user</li>
|
||||||
<?php
|
<?php
|
||||||
|
|||||||
@@ -21,17 +21,20 @@ Example code:
|
|||||||
|
|
||||||
```php
|
```php
|
||||||
use RobThree\Auth\TwoFactorAuth;
|
use RobThree\Auth\TwoFactorAuth;
|
||||||
|
use RobThree\Auth\Providers\Qr\QRServerProvider; // if using library's provider
|
||||||
use RobThree\Auth\Providers\Qr\BaconQrCodeProvider; // if using Bacon
|
use RobThree\Auth\Providers\Qr\BaconQrCodeProvider; // if using Bacon
|
||||||
use RobThree\Auth\Providers\Qr\EndroidQrCodeProvider; // if using Endroid
|
use RobThree\Auth\Providers\Qr\EndroidQrCodeProvider; // if using Endroid
|
||||||
|
|
||||||
|
// using the default Qr Code provider from the library
|
||||||
|
$tfa = new TwoFactorAuth(new QRServerProvider(), "Your app name");
|
||||||
// using Bacon
|
// using Bacon
|
||||||
$tfa = new TwoFactorAuth(new BaconQrCodeProvider());
|
$tfa = new TwoFactorAuth(new BaconQrCodeProvider(), "Your app name");
|
||||||
// using Endroid
|
// using Endroid
|
||||||
$tfa = new TwoFactorAuth(new EndroidQrCodeProvider());
|
$tfa = new TwoFactorAuth(new EndroidQrCodeProvider(), "Your app name");
|
||||||
// using a custom object implementing IQRCodeProvider interface
|
// using a custom object implementing IQRCodeProvider interface
|
||||||
$tfa = new TwoFactorAuth(new MyQrCodeProvider());
|
$tfa = new TwoFactorAuth(new MyQrCodeProvider(), "Your app name");
|
||||||
// using named argument and a variable
|
// using named argument and a variable
|
||||||
$tfa = new TwoFactorAuth(qrcodeprovider: $qrGenerator);
|
$tfa = new TwoFactorAuth(qrcodeprovider: $qrGenerator, issuer: "Your app name");
|
||||||
```
|
```
|
||||||
|
|
||||||
## 3. Shared secrets
|
## 3. Shared secrets
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ abstract class BaseHTTPQRCodeProvider implements IQRCodeProvider
|
|||||||
throw new QRException(curl_error($curlhandle));
|
throw new QRException(curl_error($curlhandle));
|
||||||
}
|
}
|
||||||
|
|
||||||
curl_close($curlhandle);
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,10 +28,13 @@ class EndroidQrCodeProvider implements IQRCodeProvider
|
|||||||
|
|
||||||
protected $endroid5 = false;
|
protected $endroid5 = false;
|
||||||
|
|
||||||
|
protected $endroid6 = false;
|
||||||
|
|
||||||
public function __construct($bgcolor = 'ffffff', $color = '000000', $margin = 0, $errorcorrectionlevel = 'H')
|
public function __construct($bgcolor = 'ffffff', $color = '000000', $margin = 0, $errorcorrectionlevel = 'H')
|
||||||
{
|
{
|
||||||
$this->endroid4 = method_exists(QrCode::class, 'create');
|
|
||||||
$this->endroid5 = enum_exists(ErrorCorrectionLevel::class);
|
$this->endroid5 = enum_exists(ErrorCorrectionLevel::class);
|
||||||
|
$this->endroid6 = $this->endroid5 && !method_exists(QrCode::class, 'setSize');
|
||||||
|
$this->endroid4 = $this->endroid6 || method_exists(QrCode::class, 'create');
|
||||||
|
|
||||||
$this->bgcolor = $this->handleColor($bgcolor);
|
$this->bgcolor = $this->handleColor($bgcolor);
|
||||||
$this->color = $this->handleColor($color);
|
$this->color = $this->handleColor($color);
|
||||||
@@ -56,6 +59,17 @@ class EndroidQrCodeProvider implements IQRCodeProvider
|
|||||||
|
|
||||||
protected function qrCodeInstance(string $qrText, int $size): QrCode
|
protected function qrCodeInstance(string $qrText, int $size): QrCode
|
||||||
{
|
{
|
||||||
|
if ($this->endroid6) {
|
||||||
|
return new QrCode(
|
||||||
|
data: $qrText,
|
||||||
|
errorCorrectionLevel: $this->errorcorrectionlevel,
|
||||||
|
size: $size,
|
||||||
|
margin: $this->margin,
|
||||||
|
foregroundColor: $this->color,
|
||||||
|
backgroundColor: $this->bgcolor
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
$qrCode = new QrCode($qrText);
|
$qrCode = new QrCode($qrText);
|
||||||
$qrCode->setSize($size);
|
$qrCode->setSize($size);
|
||||||
|
|
||||||
@@ -63,7 +77,6 @@ class EndroidQrCodeProvider implements IQRCodeProvider
|
|||||||
$qrCode->setMargin($this->margin);
|
$qrCode->setMargin($this->margin);
|
||||||
$qrCode->setBackgroundColor($this->bgcolor);
|
$qrCode->setBackgroundColor($this->bgcolor);
|
||||||
$qrCode->setForegroundColor($this->color);
|
$qrCode->setForegroundColor($this->color);
|
||||||
|
|
||||||
return $qrCode;
|
return $qrCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -33,11 +33,15 @@ class EndroidQrCodeWithLogoProvider extends EndroidQrCodeProvider
|
|||||||
|
|
||||||
$logo = null;
|
$logo = null;
|
||||||
if ($this->logoPath) {
|
if ($this->logoPath) {
|
||||||
$logo = Logo::create($this->logoPath);
|
if ($this->endroid6) {
|
||||||
if ($this->logoSize) {
|
$logo = new Logo($this->logoPath, ...$this->logoSize);
|
||||||
$logo->setResizeToWidth($this->logoSize[0]);
|
} else {
|
||||||
if (isset($this->logoSize[1])) {
|
$logo = Logo::create($this->logoPath);
|
||||||
$logo->setResizeToHeight($this->logoSize[1]);
|
if ($this->logoSize) {
|
||||||
|
$logo->setResizeToWidth($this->logoSize[0]);
|
||||||
|
if (isset($this->logoSize[1])) {
|
||||||
|
$logo->setResizeToHeight($this->logoSize[1]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user