registerPolicies(); Auth::viaRequest('api-token', function (Request $request) { // https://stackoverflow.com/questions/25838183/what-is-the-oauth-2-0-bearer-token-exactly/25843058 /** * Un token devrais ĂȘtre fourni pour chaque requete apres authentification * api_token param est requis par Auth */ $apiToken = $request->api_token; if (is_null($apiToken)) { return null; } /** ** All ApiV2 routes must pass Brand model to controller action since a Brand owns ** a service token, otherwise the api cannot be called. ** This hack is a custom binder instead of passing ** this to route as a parameter */ if (!($route = Helper::getRoute($request))) { return null; } 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; } }); } }