Portier client for PHP
Switch branches/tags
Nothing to show
Clone or download
Latest commit dcb7e07 Jan 5, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src Add a normalize helper Jan 5, 2018
tests Initial commit Nov 4, 2016
.gitignore Initial commit Nov 4, 2016
.travis.yml Add phpstan Sep 29, 2017
LICENSE Initial commit Nov 4, 2016
README.md Initial commit Nov 4, 2016
composer.json Upgrade to PHPStan 0.9 Dec 4, 2017
phpunit.xml Initial commit Nov 4, 2016

README.md

portier-php

A Portier client library for PHP

Example

<?php

require 'vendor/autoload.php';

$app = new \Slim\App();

$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->getParsedBodyParam('email'));

    return $res
        ->withStatus(303)
        ->withHeader('Location', $authUrl);
});

$app->post('/verify', function($req, $res) use ($portier) {
    $email = $portier->verify($req->getParsedBodyParam('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();