PHP code example of dmt-software / auth-middleware
1. Go to this page and download the library: Download dmt-software/auth-middleware 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/ */
dmt-software / auth-middleware example snippets
use DMT\Auth\Authorization\ApiToken;
use DMT\Auth\AuthorizationMiddleware;
use GuzzleHttp\Client;
use GuzzleHttp\Handler\CurlHandler;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Middleware;
$stack = new HandlerStack();
$stack->setHandler(new CurlHandler());
$stack->push(Middleware::mapRequest(new AuthorizationMiddleware(new ApiToken('abc123abc123'))));
$client = new Client([
'handler' => $stack
]);
$response = $client->get('https://api.localhost.dev'); // api token is added before the request is sent.