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
114 lines
4 KiB
PHP
114 lines
4 KiB
PHP
<?php
|
|
|
|
namespace App\Enums;
|
|
|
|
use Kwaadpepper\Enum\BaseEnumRoutable;
|
|
|
|
/**
|
|
* This describes an API error.
|
|
*
|
|
* @method static self modelNotFound()
|
|
* The request model was not found (typically the customer)
|
|
*
|
|
* @method static self validationFailed()
|
|
* This means some data could not be validated,
|
|
* you may have to look into message to get the details
|
|
*
|
|
* @method static self customerExists()
|
|
* The customer already exists
|
|
*
|
|
* @method static self customerNotActivated()
|
|
* The customer account is not activated and cannot perform
|
|
* this action
|
|
*
|
|
* @method static self customerAlreadyActive()
|
|
* You have requested to activate a customer account,
|
|
* but it is already active
|
|
*
|
|
* @method static self singleOptinCustomerExists()
|
|
* You have requested to create a single optin for an email,
|
|
* but it already exists
|
|
*
|
|
* @method static self apiAuthFailed()
|
|
* The authentification to the api failed. You may have to
|
|
* check into config or .env file for your service credentials
|
|
*
|
|
* @method static self authFailed()
|
|
* The authentification for this customer failed because of wrong credentials
|
|
*
|
|
* @method static self methodNotAllowed()
|
|
* This http method is not allowed
|
|
*
|
|
* @method static self wrongTimeStamp()
|
|
* The timestamp given is wrong. This would happen in case if
|
|
* a replay attack scenario. Timestamps are provided in headers
|
|
* and in the http body
|
|
*
|
|
* @method static self missingParameter()
|
|
* The request is missing some parameters
|
|
*
|
|
* @method static self throttleRequestsException()
|
|
* Too many requests have been attempted. The is a throttle security.
|
|
* Normally you should not trigger this.
|
|
* If this happens fill a ticket on https://supportweb.ldc.fr
|
|
* with some technical details
|
|
*
|
|
* @method static self authorizationException()
|
|
* You are maybe trying to access data that is out of your range.
|
|
* This should not happen normally, it is here to allow you to handle this case.
|
|
* If this happens fill a ticket on https://supportweb.ldc.fr
|
|
* with some technical details
|
|
*
|
|
* @package LDCCrmClient
|
|
* @subpackage enums
|
|
*/
|
|
class ApiError extends BaseEnumRoutable
|
|
{
|
|
/**
|
|
* Valeurs des possibilités de cet énumération (value)
|
|
*
|
|
* @return array
|
|
*/
|
|
public static function values(): array
|
|
{
|
|
return [
|
|
'modelNotFound' => 101,
|
|
'validationFailed' => 102,
|
|
'customerExists' => 103,
|
|
'customerAlreadyActive' => 110,
|
|
'customerNotActivated' => 116,
|
|
'authFailed' => 117,
|
|
'apiAuthFailed' => 119,
|
|
'singleOptinCustomerExists' => 120,
|
|
'methodNotAllowed' => 150,
|
|
'wrongTimeStamp' => 151,
|
|
'missingParameter' => 400,
|
|
'authorizationException' => 403,
|
|
'throttleRequestsException' => 429
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Libellés des possibilités de cet énumération (label)
|
|
*
|
|
* @return array
|
|
*/
|
|
public static function labels(): array
|
|
{
|
|
return [
|
|
'modelNotFound' => '%s introuvable.',
|
|
'validationFailed' => 'Impossible de valider les données',
|
|
'customerExists' => 'L\'utilisateur est déjà enregistré sur ce site',
|
|
'customerNotActivated' => 'Le compte n\'est pas activé',
|
|
'customerAlreadyActive' => 'Le compte est déjà activé',
|
|
'singleOptinCustomerExists' => 'Le single optin ne peut être ajouté car un compte existe.',
|
|
'authFailed' => 'Echec de l\'authentification du compte',
|
|
'apiAuthFailed' => 'Echec de l\'authentification client à l\'Api LDC-CRM pour ce service',
|
|
'methodNotAllowed' => 'This method is not allowed for this request',
|
|
'wrongTimeStamp' => 'Your request is malformed, please check timestamp header and parameter',
|
|
'missingParameter' => 'The request is missing some parameters',
|
|
'authorizationException' => 'You are not autorized to access this',
|
|
'throttleRequestsException' => 'Throttle: too many request have been attempted, please retry later'
|
|
];
|
|
}
|
|
}
|