where('user_id', $request->user()->id) ->where('key_type', ApiKey::TYPE_APPLICATION) ->where('r_nodes', 1) ->first(); // We couldn't find a key that exists for this user with only permission for // reading nodes. Go ahead and create it now. if (!$key) { $key = $this->keyCreationService->setKeyType(ApiKey::TYPE_APPLICATION)->handle([ 'user_id' => $request->user()->id, 'memo' => 'Automatically generated node deployment key.', 'allowed_ips' => [], ], ['r_nodes' => 1]); } return new JsonResponse([ 'node' => $node->id, 'token' => $key->identifier . $this->encrypter->decrypt($key->token), ]); } }