From 006f513cd13092fdc1e65a3f368b2f83985cd1c6 Mon Sep 17 00:00:00 2001 From: Pagan Gazzard Date: Mon, 8 Jul 2024 18:02:45 +0100 Subject: [PATCH] Avoid creating a provisioning api key when registering a device Change-type: patch --- src/models/device.ts | 44 +++++++++++++++++++++----------------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/src/models/device.ts b/src/models/device.ts index 4ea9789ce..4da93d20f 100644 --- a/src/models/device.ts +++ b/src/models/device.ts @@ -1382,29 +1382,25 @@ const getDeviceModel = function ( $expand: { is_for__device_type: deviceTypeOptions }, } as const; - const [{ id: userId }, apiKey, application, deviceType] = - await Promise.all([ - sdkInstance.auth.getUserInfo(), - sdkInstance.models.application.generateProvisioningKey( - applicationSlugOrUuidOrId, - ), - sdkInstance.models.application.get( - applicationSlugOrUuidOrId, - applicationOptions, - ) as Promise>, - typeof deviceTypeSlug === 'string' - ? (sdkInstance.models.deviceType.get(deviceTypeSlug, { - $select: 'slug', - $expand: { - is_of__cpu_architecture: { - $select: 'slug', - }, + const [{ id: userId }, application, deviceType] = await Promise.all([ + sdkInstance.auth.getUserInfo(), + sdkInstance.models.application.get( + applicationSlugOrUuidOrId, + applicationOptions, + ) as Promise>, + typeof deviceTypeSlug === 'string' + ? (sdkInstance.models.deviceType.get(deviceTypeSlug, { + $select: 'slug', + $expand: { + is_of__cpu_architecture: { + $select: 'slug', }, - }) as Promise< - PineTypedResult - >) - : null, - ]); + }, + }) as Promise< + PineTypedResult + >) + : null, + ]); if (deviceType != null) { const isCompatibleParameter = sdkInstance.models.os.isArchitectureCompatibleWith( @@ -1423,7 +1419,9 @@ const getDeviceModel = function ( applicationId: application.id, uuid, deviceType: (deviceType ?? application.is_for__device_type[0]).slug, - provisioningApiKey: apiKey, + // This just needs to be auth that can create the device, so using user auth is just fine and avoids + // creating an api key unnecessarily + provisioningApiKey: await sdkInstance.auth.getToken(), apiEndpoint: apiUrl, }); },