encrypter = $encrypter; $this->keyCreationService = $keyCreationService; $this->repository = $repository; } /** * Returns all of the API keys that exist for the given client. * * @return array */ public function index(ClientApiRequest $request) { return $this->fractal->collection($request->user()->apiKeys) ->transformWith($this->getTransformer(ApiKeyTransformer::class)) ->toArray(); } /** * Store a new API key for a user's account. * * @return array * * @throws \Pterodactyl\Exceptions\DisplayException */ public function store(StoreApiKeyRequest $request) { if ($request->user()->apiKeys->count() >= 5) { throw new DisplayException('You have reached the account limit for number of API keys.'); } $token = $request->user()->createToken( $request->input('description'), $request->input('allowed_ips') ); return $this->fractal->item($token->accessToken) ->transformWith($this->getTransformer(ApiKeyTransformer::class)) ->addMeta(['secret_token' => $token->plainTextToken]) ->toArray(); } /** * Deletes a given API key. * * @return \Illuminate\Http\JsonResponse */ public function delete(ClientApiRequest $request, string $identifier) { $response = $this->repository->deleteWhere([ 'key_type' => ApiKey::TYPE_ACCOUNT, 'user_id' => $request->user()->id, 'identifier' => $identifier, ]); if (!$response) { throw new NotFoundHttpException(); } return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT); } }