Merge branch 'trunk'
This commit is contained in:
commit
7da3f48ece
4 changed files with 41 additions and 11 deletions
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
namespace App\Providers;
|
||||
|
||||
use App\Enums\ApiError;
|
||||
use App\Exceptions\Api\V2\ApiErrorException;
|
||||
use App\Lib\Helper;
|
||||
use App\Models\Service;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
|
|
@ -37,7 +39,7 @@ class AuthServiceProvider extends ServiceProvider
|
|||
$apiToken = $request->api_token;
|
||||
|
||||
if (is_null($apiToken)) {
|
||||
return null;
|
||||
throw new ApiErrorException(ApiError::apiAuthFailed(), 401);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -47,20 +49,22 @@ class AuthServiceProvider extends ServiceProvider
|
|||
** this to route as a parameter
|
||||
*/
|
||||
if (!($route = Helper::getRoute($request))) {
|
||||
return null;
|
||||
throw new ApiErrorException(ApiError::apiAuthFailed(), 401);
|
||||
}
|
||||
|
||||
try {
|
||||
$service = Service::getFromApiToken($apiToken);
|
||||
$service = $service->load('brand');
|
||||
app()->bind(Service::class, function () use ($service) {
|
||||
return $service;
|
||||
});
|
||||
$test = $service->authenticateApi($apiToken);
|
||||
return $test ? $service : null;
|
||||
} catch (ModelNotFoundException $e) {
|
||||
return null;
|
||||
throw new ApiErrorException(ApiError::apiAuthFailed(), 401);
|
||||
}
|
||||
$service = $service->load('brand');
|
||||
app()->bind(Service::class, function () use ($service) {
|
||||
return $service;
|
||||
});
|
||||
if ($service->authenticateApi($apiToken)) {
|
||||
return $service;
|
||||
}
|
||||
throw new ApiErrorException(ApiError::apiAuthFailed(), 401);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
Subproject commit 0fa8c8d691f72c9d48a5db296a830920ef25534a
|
||||
Subproject commit b4982ab41b2d2df4bd0ec43b2e300c701aaa0184
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "ldc/ldccrmv2client",
|
||||
"type": "project",
|
||||
"version": "2.1.7",
|
||||
"version": "2.1.8",
|
||||
"description": "LDC CRM V2",
|
||||
"authors": [
|
||||
{
|
||||
|
|
|
|||
|
|
@ -64,6 +64,32 @@ class CustomerTest extends ApiBase
|
|||
$this->assertNotEmpty($json->json('data.hashcode'));
|
||||
}
|
||||
|
||||
/**
|
||||
* route: apiV2.customers.authenticate
|
||||
*/
|
||||
public function testApiAuthenticateCustomerShouldFail()
|
||||
{
|
||||
extract($this->getCustomer());
|
||||
$response = $this->callApiWithToken(
|
||||
$service,
|
||||
'post',
|
||||
route('apiV2.customers.authenticate', []),
|
||||
[
|
||||
'email' => $customer->email,
|
||||
'password' => 'testPasswords'
|
||||
]
|
||||
);
|
||||
|
||||
$json = $response->decodeResponseJson();
|
||||
|
||||
$this->assertApiResponseStatusIs($json, ApiStatus::KO());
|
||||
$this->assertNotEmpty($json->json('data'));
|
||||
$this->assertNotEmpty($json->json('data.message'));
|
||||
$this->assertNotEmpty($json->json('data.code'));
|
||||
$this->assertEquals(ApiError::authFailed()->value, $json->json('data.code'));
|
||||
$this->assertEquals(ApiError::authFailed()->label, $json->json('data.message'));
|
||||
}
|
||||
|
||||
/**
|
||||
* route: apiV2.customers.store
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue