Fix up API handling logic for keys and set a prefix on all keys

This commit is contained in:
DaneEveritt 2022-05-22 19:03:51 -04:00
parent 8605d175d6
commit b051718afe
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
11 changed files with 88 additions and 31 deletions

View file

@ -63,7 +63,6 @@ class ApiKeyController extends ClientApiController
* @return array
*
* @throws \Pterodactyl\Exceptions\DisplayException
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
*/
public function store(StoreApiKeyRequest $request)
{
@ -71,17 +70,14 @@ class ApiKeyController extends ClientApiController
throw new DisplayException('You have reached the account limit for number of API keys.');
}
$key = $this->keyCreationService->setKeyType(ApiKey::TYPE_ACCOUNT)->handle([
'user_id' => $request->user()->id,
'memo' => $request->input('description'),
'allowed_ips' => $request->input('allowed_ips') ?? [],
]);
$token = $request->user()->createToken(
$request->input('description'),
$request->input('allowed_ips')
);
return $this->fractal->item($key)
return $this->fractal->item($token->accessToken)
->transformWith($this->getTransformer(ApiKeyTransformer::class))
->addMeta([
'secret_token' => $this->encrypter->decrypt($key->token),
])
->addMeta(['secret_token' => $token->plainTextToken])
->toArray();
}