PHP code example of anfly0 / psr-15-github-auth

1. Go to this page and download the library: Download anfly0/psr-15-github-auth library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

anfly0 / psr-15-github-auth example snippets



/**
 * Minimal example using slim 4.0.0-beta and monolog 
 */
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Factory\AppFactory;
use Slim\Psr7\Factory\StreamFactory;

use Monolog\Logger;
use Monolog\Handler\StreamHandler;

use Anfly0\Middleware\GitHub\Auth;

to the contents of php://input.
$body = function (Request $request, $handler) {
    if ($request->getBody()->getSize() === 0) {
        $streamFactory = new StreamFactory();
        $request = $request->withBody($streamFactory->createStreamFromFile('php://input'));
    }
    return $handler->handle($request);
};


// Setup route and add middleware
$app->post('/', function (Request $request, Response $response, $args) {
    $response->getBody()->write('OK');
    return $response;
})
->addMiddleware($auth)
->add($body);

$app->run();