Download the PHP package tracesoftwareinternational/elephant-guard without Composer
On this page you can find all versions of the php package tracesoftwareinternational/elephant-guard. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download tracesoftwareinternational/elephant-guard
More information about tracesoftwareinternational/elephant-guard
Files in tracesoftwareinternational/elephant-guard
Package elephant-guard
Short Description PSR-7 and PSR-15 HTTP compliant middleware
License GPL-3.0
Informations about the package elephant-guard
Elephant Guard
This middleware is meant to apply a given AuthenticatorInterface
on a given set of routes.
It can be used with all frameworks using PSR-7 or PSR-15 style middlewares. It has been tested with Slim Framework.
Credits
Huge thanks to Mika Tuupola for his greatly structured PSR-15 compliant middlewares that inspired us (thinking of slim-jwt-auth and slim-basic-auth), Elephant Guard contains some of his work, a lot of thanks Mika !
Install
Install latest version using composer.
Usage
Configuration options are passed as an array. Only mandatory parameter is authenticator
.
For more information, please refer to Parameters.
Parameters
Authenticator
The main purpose of this library is to test an incoming request against a class that implements AuthenticatorInterface
By example, you could use a random based authentication :
Same thing can also be accomplished with anonymous class declaration.
Path
The optional path
parameter allows you to specify the protected part of your website. It can be either a string or an array. You do not need to specify each URL. Instead think of path
setting as a folder. In the example below everything starting with /api
will be authenticated.
Ignore
With optional ignore
parameter you can make exceptions to path
parameter. In the example below everything starting with /api
and /admin
will be authenticated with the exception of /api/token
and /admin/ping
which will not be authenticated.
You may use the Glob syntax as supported by webmozart/glob to ignore routes with parameters in URL (like /products/123456
)
Before
Before function is called only when authentication succeeds but before the next incoming middleware is called. You can use this to alter the request before passing it to the next incoming middleware in the stack. If it returns anything else than \Psr\Http\Message\RequestInterface
the return value will be ignored.
After
After function is called only when authentication succeeds and after the incoming middleware stack has been called. You can use this to alter the response before passing it next outgoing middleware in the stack. If it returns anything else than \Psr\Http\Message\ResponseInterface
the return value will be ignored.
Setting response body when authentication fails
By default Elephant Guard returns an empty response body with 401 response and an array of "arguments".
arguments will be an array containing two indexes :
message
: the reason why it failedauthenticatorError
: the last error retrieved from the provided authenticator
You can return custom body using by providing an error handler. This is useful for example when you need additional information why authentication failed.
Testing
You can run tests manually with composer :
License
The GNU General Public License v3.0 (GPL v3.0). Please see License File for more information.
All versions of elephant-guard with dependencies
psr/http-message Version ^1.0
psr/http-server-middleware Version ^1.0
tuupola/callable-handler Version ^1.0
tuupola/http-factory Version ^1.0
webmozart/glob Version ^4.1