robertogallea/laravel-greenpass

There is no license information available for the latest version (0.2.2) of this package.

European green-pass decoding and validation for php/laravel

0.2.2 2021-12-15 10:18 UTC

This package is auto-updated.

Last update: 2024-10-15 16:37:35 UTC


README

Laravel Green Pass

laravel-greenpass

Author GitHub release (latest SemVer) Laravel >=6.0 Software License PSR2 Conformance Sponsor me! Packagist Downloads

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);