portier / client
Portier client for PHP
Installs: 34 025
Dependents: 0
Suggesters: 0
Security: 0
Stars: 7
Watchers: 4
Forks: 2
Open Issues: 0
Requires
- fgrosse/phpasn1: ^2.3.1
- guzzlehttp/guzzle: ^7.2.0
- lcobucci/clock: ^2.0.0 || ^3.0.0
- lcobucci/jwt: ^4.1.0 || ^5.0.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.14
- phpstan/phpstan: ^1.2.0
- phpunit/phpunit: ^9.5 || ^10.4.2
README
A Portier client library for PHP.
Example
<?php require 'vendor/autoload.php'; $app = \Slim\Factory\AppFactory::create(); $app->addRoutingMiddleware(); $app->addErrorMiddleware(true, true, true); $redis = new Redis(); $redis->pconnect('127.0.0.1', 6379); $portier = new \Portier\Client\Client( new \Portier\Client\RedisStore($redis), 'http://localhost:8000/verify' ); $app->get('/', function($req, $res) { $res = $res ->withStatus(200) ->withHeader('Content-Type', 'text/html; charset=utf-8'); $res->getBody()->write( <<<EOF <p>Enter your email address:</p> <form method="post" action="/auth"> <input name="email" type="email"> <button type="submit">Login</button> </form> EOF ); return $res; }); $app->post('/auth', function($req, $res) use ($portier) { $authUrl = $portier->authenticate($req->getParsedBody()['email']); return $res ->withStatus(303) ->withHeader('Location', $authUrl); }); $app->post('/verify', function($req, $res) use ($portier) { $email = $portier->verify($req->getParsedBody()['id_token']); $res = $res ->withStatus(200) ->withHeader('Content-Type', 'text/html; charset=utf-8'); $res->getBody()->write( <<<EOF <p>Verified email address ${email}!</p> EOF ); return $res; }); $app->run();