joskoomen / abstract-api
This package is abandoned and no longer maintained.
The author suggests using the ypa/abstract-api package instead.
Abstract package for extra security in API's
1.5.0
2019-11-18 13:23 UTC
Requires
- joskoomen/guzzlehttp: 1.*
- nesbot/carbon: ^2.26
README
Laravel
- Add the Service Provider to
config/app.php
/*
* Package Service Providers...
*/
\Ypa\AbstractApi\AbstractApiServiceProvider::class,
- Run
php artisan vendor:publish
to publish the config file; - Add the
.env
variables and their values; - Add the middleware in
App\Http\Kernel.php
to$routeMiddleware
'abstract.api' => \Ypa\AbstractApi\AbstractApiMiddleware::class,
- And i advice to add it to the
api
group in the same file:
'api' => [
'throttle:60,1',
'bindings',
'abstract.api
],
- For sending you can add the
AbstractApiValidationTrait
to your controller. - Right before your API request you can use the following method:
$form_params = $this->addTimeAndSignature(request()->all());
That's it!
Lumen
- Add the
.env
variables and their values;
YPA_ABSTRACT_API_TIME_DIFFERENCES=30
YPA_ABSTRACT_API_HASH_SECRET="${APP_KEY}"
YPA_ABSTRACT_API_HASHTYPE=sha512
YPA_ABSTRACT_API_DEBUG=true
YPA_ABSTRACT_API_DISABLE=false
- Add the middleware in your bootstrap file.
$app->routeMiddleware([
'abstract.api' => \Ypa\AbstractApi\AbstractApiMiddleware::class,
]);,
- Add the middleware to your routes you want to secure like any other middleware in Lumen.
- For sending you can add the
AbstractApiValidationTrait
to your controller. - Right before your API request you can use the following method:
$form_params = $this->addTimeAndSignature(request()->all());
That's it!