Phase 0: Fundament für Inhaus
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 1m14s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 1m12s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 1m7s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 1m19s
CI / PHP 8.3 / mysql:8.0 (pull_request) Successful in 1m32s
CI / PHP 8.4 / mysql:8.0 (pull_request) Successful in 1m22s
CI / PHP 8.4 / mysql:8.4 (pull_request) Successful in 1m32s
CI / PHP 8.3 / mysql:8.4 (pull_request) Successful in 1m35s
CI / Build-Artefakte aktuell (pull_request) Failing after 1m7s

- Laravel 13 mit Filament 5 (Admin), Inertia 3 + Vue 3 + Vuetify 4 (Material 3)
- Anmeldung über Fortify (Login, Passwort vergessen/ändern), keine Selbstregistrierung
- Profil mit Profilbild (WebP in festen Größen), Personenseiten, Header mit Avatar-Menü
- Material-3-Farbschema aus der Primärfarbe, hell/dunkel/System pro Person
- Basis-Branding (Portalname, Logo, Primärfarbe) im Admin unter „Erscheinungsbild“
- Benutzerverwaltung im Admin, Zugang vorläufig über is_admin
- vendor/ (ohne Dev-Pakete) und Frontend-Build mitversioniert, Dev-Pakete in vendor-dev/
- PHPUnit-Tests gegen MySQL/MariaDB, Forgejo-CI-Matrix, Docker-Entwicklungsumgebung
- VERSION, CHANGELOG.md und CONTRIBUTING.md mit Release-Ablauf

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Friederich Loheide 2026-09-25 20:35:30 +00:00
parent 7197eaebf2
commit 9c0f8de791
15771 changed files with 1564103 additions and 5 deletions

View file

@ -0,0 +1,7 @@
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.

View file

@ -0,0 +1,159 @@
# 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://github.com/antonioribeiro/google2fa-qrcode/actions/workflows/phpunit.yml"><img alt="PHPUnit" src="https://github.com/antonioribeiro/google2fa-qrcode/actions/workflows/phpunit.yml/badge.svg"></a>
<a href="https://github.com/antonioribeiro/google2fa-qrcode/actions/workflows/phpstan.yml"><img alt="PHPStan" src="https://github.com/antonioribeiro/google2fa-qrcode/actions/workflows/phpstan.yml/badge.svg"></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://codecov.io/gh/antonioribeiro/google2fa-qrcode"><img alt="Coverage" src="https://codecov.io/gh/antonioribeiro/google2fa-qrcode/branch/4.x/graph/badge.svg"></a>
<a href="https://www.php.net"><img alt="PHP" src="https://img.shields.io/badge/PHP-8.1%20--%208.5-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).
## Version Compatibility
| PHP | `pragmarx/google2fa-qrcode` |
| ------------ | --------------------------- |
| `7.1` | `3.x` |
| `7.2` | `3.x` |
| `7.3` | `3.x` |
| `7.4` | `3.x` |
| `8.0` | `3.x` |
| `8.1` | `4.x` |
| `8.2` | `4.x` |
| `8.3` | `4.x` |
| `8.4` | `4.x` |
| `8.5` | `4.x` |
## 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 Chillerlan or BaconQrCode package, 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:
![QRCode](https://chart.googleapis.com/chart?chs=200x200&chld=M|0&cht=qr&chl=otpauth%3A%2F%2Ftotp%2FPragmaRX%3Aacr%2Bpragmarx%40antoniocarlosribeiro.com%3Fsecret%3DADUMJO5634NPDEKW%26issuer%3DPragmaRX)
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 different 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.

View file

@ -0,0 +1,42 @@
{
"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": "^8.1",
"pragmarx/google2fa": "^8.0|^9.0"
},
"require-dev": {
"phpunit/phpunit": "~9|~10|~11|~12|~13",
"khanamiryan/qrcode-detector-decoder": "^1.0",
"bacon/bacon-qr-code": "^2.0|^3.0",
"chillerlan/php-qrcode": "^5.0|^6.0",
"phpstan/phpstan": "^2.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
}

View file

@ -0,0 +1,4 @@
parameters:
level: max
paths:
- src

View file

@ -0,0 +1,9 @@
<?php
namespace PragmaRX\Google2FAQRCode\Exceptions;
use Exception;
class MissingQRCodeServiceException extends Exception
{
}

View file

@ -0,0 +1,93 @@
<?php
namespace PragmaRX\Google2FAQRCode;
use BaconQrCode\Renderer\Image\ImageBackEndInterface;
use BaconQrCode\Renderer\ImageRenderer;
use BaconQrCode\Writer;
use chillerlan\QRCode\QRCode;
use PragmaRX\Google2FA\Google2FA as Google2FAPackage;
use PragmaRX\Google2FAQRCode\Exceptions\MissingQRCodeServiceException;
use PragmaRX\Google2FAQRCode\QRCode\Bacon;
use PragmaRX\Google2FAQRCode\QRCode\Chillerlan;
use PragmaRX\Google2FAQRCode\QRCode\QRCodeServiceContract;
class Google2FA extends Google2FAPackage
{
/**
* @var QRCodeServiceContract|null
*/
protected $qrCodeService;
public function __construct(
?QRCodeServiceContract $qrCodeService = null,
?ImageBackEndInterface $imageBackEnd = null
) {
$this->setQRCodeService(
$qrCodeService === null
? $this->qrCodeServiceFactory($imageBackEnd)
: $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'
) {
$service = $this->getQRCodeService();
if ($service === null) {
throw new MissingQRCodeServiceException(
'You need to install a service package or assign yourself the service to be used.'
);
}
return $service->getQRCodeInline(
$this->getQRCodeUrl($company, $holder, $secret),
$size,
$encoding
);
}
public function getQRCodeService(): ?QRCodeServiceContract
{
return $this->qrCodeService;
}
public function setQRCodeService(?QRCodeServiceContract $service): self
{
$this->qrCodeService = $service;
return $this;
}
public function qrCodeServiceFactory(?ImageBackEndInterface $imageBackEnd = null): ?QRCodeServiceContract
{
if (
class_exists(Writer::class) &&
class_exists(ImageRenderer::class)
) {
return new Bacon($imageBackEnd);
}
if (class_exists(QRCode::class)) {
return new Chillerlan();
}
return null;
}
}

View file

@ -0,0 +1,77 @@
<?php
namespace PragmaRX\Google2FAQRCode\QRCode;
use BaconQrCode\Renderer\Image\ImageBackEndInterface;
use BaconQrCode\Renderer\Image\ImagickImageBackEnd;
use BaconQrCode\Renderer\Image\SvgImageBackEnd;
use BaconQrCode\Renderer\ImageRenderer;
use BaconQrCode\Renderer\RendererStyle\RendererStyle;
use BaconQrCode\Writer;
class Bacon implements QRCodeServiceContract
{
/**
* @var ImageBackEndInterface|null
*/
protected $imageBackEnd;
public function __construct(?ImageBackEndInterface $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);
}
if ($this->getImageBackend() instanceof SvgImageBackEnd) {
return 'data:image/svg+xml;base64,' . base64_encode($data);
}
return $data;
}
public function imagickIsAvailable(): bool
{
return extension_loaded('imagick');
}
public function getImageBackend(): ImageBackEndInterface
{
if ($this->imageBackEnd === null) {
$this->imageBackEnd = $this->imagickIsAvailable()
? new ImagickImageBackEnd()
: new SvgImageBackEnd();
}
return $this->imageBackEnd;
}
public function setImageBackend(ImageBackEndInterface $imageBackEnd): self
{
$this->imageBackEnd = $imageBackEnd;
return $this;
}
}

View file

@ -0,0 +1,77 @@
<?php
namespace PragmaRX\Google2FAQRCode\QRCode;
use chillerlan\QRCode\Common\EccLevel;
use chillerlan\QRCode\Common\Version;
use chillerlan\QRCode\Output\QRMarkupSVG;
use chillerlan\QRCode\QRCode;
use chillerlan\QRCode\QROptions;
class Chillerlan implements QRCodeServiceContract
{
/**
* @var array<string, mixed>
*/
protected $options = [];
protected function getOptions(): QROptions
{
return new QROptions($this->buildOptionsArray());
}
/**
* @param array<string, mixed> $options
*/
public function setOptions(array $options): self
{
$this->options = $options;
return $this;
}
/**
* @return array<string, mixed>
*/
public function buildOptionsArray(?int $size = null): array
{
$defaults = [
'version' => Version::AUTO,
'outputInterface' => QRMarkupSVG::class,
'eccLevel' => EccLevel::L,
];
$options = array_merge($defaults, $this->options);
// Let this package handle the base64 wrap so output is deterministic
// regardless of chillerlan's per-version defaults. See PR #12.
$options['outputBase64'] = false;
return $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());
$svg = $renderer->render($string);
// chillerlan's render() is typed as mixed in its source, but with
// outputInterface=QRMarkupSVG we always get a string back. Guard
// here so PHPStan can narrow the type cleanly.
if (!is_string($svg)) {
throw new \RuntimeException('chillerlan returned a non-string SVG payload.');
}
return 'data:image/svg+xml;base64,' . base64_encode($svg);
}
}

View file

@ -0,0 +1,17 @@
<?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');
}