app['auth']->viaRequest('api', function (Request $request) { // with token if ($request->bearerToken()) { return $this->loginUserWithToken($request); } // first party if ($request->getHost() === $container_name = getenv('CONTAINER_NAME')) { return $this->loginServiceWithSetUser($container_name); } // without token return null; }); } public function loginUserWithToken(Request $request): User { $attributes = Http::retry(3, 100) ->withToken($request->bearerToken()) ->get(env('USER_URL') . 'auth') ->json(); $attributes = Arr::get($attributes, 'data',[]); // dd($attributes); return new User($attributes); } public function loginServiceWithSetUser(string $container_name): User { Auth::setUser($user = new User([ 'name' => $container_name, 'is_service' => true, ])); return $user; } }