Create api for user on Pterodactyl
Updated
•1 min readIn ApiKeyController add:
public function storeforuser(StoreApiKeyRequest $request, int $userId): array
{
$user = User::find($userId);
if (!$user) {
throw new DisplayException('User not found.');
}
if ($user->apiKeys->count() >= 25) {
throw new DisplayException('You have reached the account limit for number of API keys.');
}
$token = $user->createToken(
$request->input('description'),
$request->input('allowed_ips')
);
Activity::event('user:api-key.create')
->subject($token->accessToken)
->property('identifier', $token->accessToken->identifier)
->log();
return $this->fractal->item($token->accessToken)
->transformWith($this->getTransformer(ApiKeyTransformer::class))
->addMeta(['secret_token' => $token->plainTextToken])
->toArray();
}
In api-client add:
Route::get('/api-keys', [Client\ApiKeyController::class, 'index']);
Route::post('/api-keys', [Client\ApiKeyController::class, 'store']);
Route::post('/api-keys/user/{userId}', [Client\ApiKeyController::class, 'storeforuser']);
Route::delete('/api-keys/{identifier}', [Client\ApiKeyController::class, 'delete']);
In the pterodactyl panel disable captcha
