dmt-software/auth-middleware

Authentication and authorization middleware for psr-7 request

v1.1.0 2018-05-24 09:31 UTC

This package is auto-updated.

Last update: 2024-12-25 08:39:29 UTC


README

Build Status Scrutinizer Code Quality Code Coverage

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.