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

This package is auto-updated.

Last update: 2020-04-29 10:44:35 UTC


README

Laravel

  1. Add the Service Provider to config/app.php
/*
 * Package Service Providers...
 */
\Ypa\AbstractApi\AbstractApiServiceProvider::class,
  1. Run php artisan vendor:publish to publish the config file;
  2. Add the .env variables and their values;
  3. Add the middleware in App\Http\Kernel.php to $routeMiddleware
'abstract.api' => \Ypa\AbstractApi\AbstractApiMiddleware::class,
  1. And i advice to add it to the api group in the same file:
'api' => [
    'throttle:60,1',
    'bindings',
    'abstract.api
],
  1. For sending you can add the AbstractApiValidationTrait to your controller.
  2. Right before your API request you can use the following method:
$form_params = $this->addTimeAndSignature(request()->all());

That's it!

Lumen

  1. 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
  1. Add the middleware in your bootstrap file.
$app->routeMiddleware([
    'abstract.api' => \Ypa\AbstractApi\AbstractApiMiddleware::class,
]);,
  1. Add the middleware to your routes you want to secure like any other middleware in Lumen.
  2. For sending you can add the AbstractApiValidationTrait to your controller.
  3. Right before your API request you can use the following method:
$form_params = $this->addTimeAndSignature(request()->all());

That's it!