This removes api authentification with token in favor of signature method. Refactorize code and clean up. It add more unit test plus code coverage in test/converage. - Added config.api.timestampTimeout - Added Helper::signRequest This calculates the request signature - Added more unit tests and extend code coverage. - Added rate limiter for web routes - Added RemoveSpaces Sanitizer on api requests - Added stress test suite - Changed AuthServiceProvider api-token to api-hmac - Changed CustomerSeeder to have at least of customer activated (for unit tests) - Changed used transation for saveing multiple models - Changed, in ServiceController generateApiToken to generateServicePassword - Changed, timestamp has to be send in request with a DateTime format, it also has to a UTC value - Composer added brianium/paratest - Composer update - Fixed case where removing single optin could be the wrong one (not for the good service) - Fixed customer delete - Fixed customer would not be resolved by brand. - Fixed Really check that request is json checking body content, preventing sending malformed requests - Remove ApiError::needAuth - Removed api_token - Removed ApiController::authenticate - Removed config.api.tokenTimeout - Removed Header check or usage because of HAProxy doing weird stuff - Removed lock files from gitignore - Removed memcached dependency - Removed unused questions resources api routes - Removed workspace file Migrations - Added unique index on services.bearer_token - Changed customer_id on customer_answer is nullable - Changed services.bearer_pwd length to 312 (the size of the token) - Dropped services.api_token and service.api_token_date
72 lines
2.2 KiB
PHP
72 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Http\Requests\GenerateServiceToken;
|
|
use App\Mail\ServiceCredentialRenewed;
|
|
use App\Models\Service;
|
|
use Illuminate\Support\Facades\Hash;
|
|
use Illuminate\Support\Facades\Mail;
|
|
use Kwaadpepper\CrudPolicies\Http\Requests\CrudIndexRequest;
|
|
use Kwaadpepper\CrudPolicies\Traits\CrudController;
|
|
|
|
/**
|
|
* @codeCoverageIgnore
|
|
*/
|
|
class ServiceController extends Controller
|
|
{
|
|
use CrudController {
|
|
index as crudIndex;
|
|
}
|
|
|
|
/** @var Service */
|
|
public static $modelClass = Service::class;
|
|
|
|
/**
|
|
* The Bo app layout
|
|
*
|
|
* @var string
|
|
*/
|
|
public static $layout = 'layouts.app';
|
|
|
|
/**
|
|
* Overload crud-policies index
|
|
*
|
|
* @param CrudIndexRequest $request
|
|
* @return \Illuminate\Contracts\View\View|\Illuminate\Contracts\View\Factory
|
|
*/
|
|
public function index(CrudIndexRequest $request)
|
|
{
|
|
/** @var \Illuminate\View\View */
|
|
$view = $this->crudIndex($request);
|
|
if ($request->ajax()) {
|
|
return $view;
|
|
}
|
|
return view('service.index', $view->getData());
|
|
}
|
|
|
|
/**
|
|
* Regen service credentials
|
|
*
|
|
* @param GenerateServiceToken $request
|
|
* @param Service $service
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
*/
|
|
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed, Squiz.Commenting.FunctionComment.Missing
|
|
public function generateServicePassword(GenerateServiceToken $request, Service $service)
|
|
{
|
|
/** @var \App\Models\User $user */
|
|
$user = auth()->user();
|
|
|
|
// * Special Condition for migration from v2 to v3.
|
|
$service->bearer_token = !Hash::needsRehash($service->bearer_token) ?
|
|
$service->generateBearerToken() : $service->bearer_token;
|
|
|
|
$bearerPwd = $service->generateBearerPassword();
|
|
$service->saveOrFail();
|
|
Mail::send(new ServiceCredentialRenewed($service, $user));
|
|
return back()
|
|
// phpcs:ignore Generic.Files.LineLength.TooLong
|
|
->with('error', "ATTENTION : METTEZ À JOUR LE SITE ! \nNouveau token d'API de $service->name : '$service->bearer_token' et mot de passe '$bearerPwd'");
|
|
}
|
|
}
|