chubbyphp/chubbyphp-session-storageless
Storageless persistence adapter for zend-expressive-session
dev-master / 1.0.x-dev
2019-12-10 16:58 UTC
Requires
- php: ^7.2
- zendframework/zend-expressive-session: ^1.2
- psr7-sessions/storageless: ^5.0
Requires (Dev)
- phploc/phploc: ^5.0
- zendframework/zend-stratigility: ^3.1
- zendframework/zend-diactoros: ^2.1
- chubbyphp/chubbyphp-mock: ^1.4.2
- mavimo/phpstan-junit: ^0.2.3
- php-coveralls/php-coveralls: ^2.2
- phpstan/extension-installer: ^1.0.3
- phpstan/phpstan: ^0.11.19
- phpunit/phpunit: ^8.4.3
- friendsofphp/php-cs-fixer: ^2.16.1
- infection/infection: ^0.14.3
- nunomaduro/phpinsights: ^1.11
README
Description
psr7-sessions/storageless persistence adapter for zendframework/zend-expressive-session.
Important: Once the Pull Request within psr7-sessions/storageless gets merged, this repo is not needed anymore.
Requirements
- php: ^7.2
- psr7-sessions/storageless: ^5.0
- zendframework/zend-expressive-session: ^1.2
Installation
Through Composer as chubbyphp/chubbyphp-session-storageless.
composer require chubbyphp/chubbyphp-session-storageless "^1.0"
Usage
With zend-stratigility using symmetric key (hmac)
Generate key
openssl rand -base64 32
Code
<?php declare(strict_types=1); namespace App; use Chubbyphp\Session\Storageless\PSR7StoragelessSessionPersistence; use PSR7Sessions\Storageless\Http\SessionMiddleware as PSR7SessionMiddleware; use Zend\Expressive\Session\SessionMiddleware as ZendSessionMiddleware; use Zend\Stratigility\MiddlewarePipe; $middlewarePipe = new MiddlewarePipe(); $middlewarePipe->pipe(PSR7SessionMiddleware::fromSymmetricKeyDefaults( 'JeIn7GmQJRkM4dP3T5ZfVcHk7rxyVoMzR1DptTIquFY=', 1200 )); $middlewarePipe->pipe(new ZendSessionMiddleware(new PSR7StoragelessSessionPersistence()));
With zend-stratigility using asymmetric key (rsa)
Generate key
openssl genrsa -out signatureKey 512 openssl rsa -in signatureKey -out verificationKey -outform PEM -pubout
Code
<?php declare(strict_types=1); namespace App; use Chubbyphp\Session\Storageless\PSR7StoragelessSessionPersistence; use PSR7Sessions\Storageless\Http\SessionMiddleware as PSR7SessionMiddleware; use Zend\Expressive\Session\SessionMiddleware as ZendSessionMiddleware; use Zend\Stratigility\MiddlewarePipe; $middlewarePipe = new MiddlewarePipe(); $middlewarePipe->pipe(PSR7SessionMiddleware::fromAsymmetricKeyDefaults( '-----BEGIN RSA PRIVATE KEY----- MIIBOgIBAAJBAKgrmaZQsaEXrlNahrSKzKwWOgEt0SSFlv+Onm94oWNfx7ghZ+Up cgTwFl+oNMa/AbpO2a6fTuj558/Z0SlWFdUCAwEAAQJBAKKrMf/ndDqv7mcgXMaM sDgRc+AqEnCybAIdUXHgDLRSolzH36lkg6/jrr8S1G/e7QdK2yvpVgaP/KH0zReo nMECIQDdXX1vtzxgX+zv8DTNHN3m0StHuJHGC0oaOsDOX06IZQIhAMJ7dGy8XUGy 39INUFBneNc0I4QKxG31jIs6tOe/MiixAiA9GJiORNx9HPygHIP2OIlmM0TmvqI9 LtB8/MpKKzPZoQIgGQfwtSoNSq5uFkf2ZVLb/77LL2x/WbO38heNPyKhnxECIH1T PbQ839hbekzuV+y8Me+JSUHgybVMg9BDzRXwON7f -----END RSA PRIVATE KEY-----', '-----BEGIN PUBLIC KEY----- MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKgrmaZQsaEXrlNahrSKzKwWOgEt0SSF lv+Onm94oWNfx7ghZ+UpcgTwFl+oNMa/AbpO2a6fTuj558/Z0SlWFdUCAwEAAQ== -----END PUBLIC KEY-----', 1200 )); $middlewarePipe->pipe(new ZendSessionMiddleware(new PSR7StoragelessSessionPersistence()));
Copyright
Dominik Zogg 2019