dmt-software / auth-middleware
Authentication and authorization middleware for psr-7 request
v1.1.0
2018-05-24 09:31 UTC
Requires
- php: ^7.1
- psr/http-message: ^1.0
Requires (Dev)
- guzzlehttp/guzzle: ^6.3
- phpunit/phpunit: ^7.0
README
Install
composer require dmt-software/auth-middleware
Usage
Example using GuzzleHttp\Client
<?php 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.