robertogallea / laravel-greenpass
European green-pass decoding and validation for php/laravel
Installs: 166
Dependents: 0
Suggesters: 0
Security: 0
Stars: 8
Watchers: 2
Forks: 5
Open Issues: 0
pkg:composer/robertogallea/laravel-greenpass
Requires
- php: ^7.3|^8.0
- ext-bcmath: *
- ext-gd: *
- guzzlehttp/guzzle: ^7.3
- herald-si/verificac19-sdk-php: ^1.0.5
- illuminate/support: >=6.0
- illuminate/validation: >=6.0
- khanamiryan/qrcode-detector-decoder: 1.0.5.2
- libern/qr-code-reader: ^1.0
- nesbot/carbon: ^2.16
Requires (Dev)
- orchestra/testbench: >=6.0
- phpunit/phpunit: >=9.0
README
laravel-greenpass
laravel-greenpass is a package for the management of the European Green Pass (i.e. covid certification).
The package allows easy validation and decoding of the GreenPass. It is also suited for Laravel since it provides a
convenient custom validator for request validation.
Installation
Run the following command to install the latest applicable version of the package:
composer require robertogallea/laravel-greenpass
Laravel
In your app config, add the Service Provider to the $providers array (only for Laravel 5.4 or below):
'providers' => [ ... robertogallea\LaravelGreenPass\GreenPassServiceProvider::class, ],
Lumen
In bootstrap/app.php, register the Service Provider
$app->register(robertogallea\LaravelGreenPass\GreenPassServiceProvider::class);
Configuration
By default, the underlying validation package saves the validation certificates inside
storage/app/public/green_pass_cache.
If you want to change this folder, publish the config file with the command
php artisan vendor:publish --provider="robertogallea\LaravelGreenPass\GreenPassServiceProvider" --tag="config"
and edit the certificate-storage-path key inside the config/green-pass.php file.
Make sure the chosen folder has write access!
Validation
To validate the formal correctness of a green pass, use the greenpass and greenpass_file keyword in your validation rules array. Please note that in this way you don't check that the green pass is actually valid (i.e. not expired or revoked).
public function rules() { return [ 'greenpass_string' => 'greenpass', //... ]; }
public function rules() { return [ 'greenpass_uploaded_file' => 'greenpass_file', //... ]; }
To perform strict validation (i.e. check actual validity) you can add the active parameter to the validator rule:
public function rules() { return [ 'greenpass_string' => 'greenpass:active', //... ]; }
public function rules() { return [ 'greenpass_uploaded_file' => 'greenpass_file:active', //... ]; }
Utility GreenPassDecoder class
A green pass can be read using the GreenPassDecoder service:
use robertogallea\LaravelGreenPass\GreenPassDecoder; ... $greenpass = new GreenPassDecoder(); $result = $greenpass->decode('HC1:...'); var_dump($result); // or $result = $greenpass->decodeFile('/path/to/file'); var_dump($result);
You can also use the GreenPass facade:
use robertogallea\LaravelGreenPass\GreenPassDecoder; ... $result = \GreenPass::decode('HC1:...'); var_dump($result); // or $result = \GreenPass::decodeFile('/path/to/file'); var_dump($result);