The Device Provisioning Service (DPS) is a helper service that enables zero-touch, just-in-time provisioning to the right data hub without requiring human intervention.

## ¶ Provisioning process

1. The device manufacturer adds the provisioning service information and registration token to the device during the initial setup/install.
2. The device manufacturer takes the registration token information and adds it to the enrollment list either through the Web API or through the online portal. The list contains the complete record of devices that may at some point register.
3. The device contacts the DPS endpoint provided in the provisioning service information at the device setup and passes the registration token to prove its identity.
4. DPS validates the identity of the device by validating the registration token against the enrollment list. If the device is not present in the enrollment list, the DPS will return a an Http 400 error to the device.
5. DPS registers the device with a service bus and initiates the device's digital twin.
6. DPS returns the service bus connection information to the device. The device can now start sending data directly to the service bus.

> In this setup the registration token should be the Balena Id of the CoFyBox

## ¶ Device registration example

Sandbox Swagger documentation

Request

    POST - https://cofybox-dps-dev.azurewebsites.net/api/v1/devices

    {
        "registrationToken": {{registrationToken}},
        "properties": {
        "displayName": "fried-time"
      }
    }

- registrationToken - string (required): The token used to identify the device and validate its enrollment.

- properties:

  - displayName - string: The name for the digital twin.

Response

    {
      "serviceBus": {
            "assignedQueue": {{serviceBusUrl}},
      	"authorizationHeaderValue": "SharedAccessSignature {{signature}}"
      },
        "api": {
        "baseUrl": {{baseUrl}},
        "authorizationHeaderValue": "apikey {{key}}"
      },
      "createdDateTimeUtc": "2020-10-30T12:44:25.0333224Z",
        "cloudSpaceUrl": {{cloudSpaceUrl}}
    }

- serviceBus.assignedQueue: The url to which the device can send its data. Read the hub listener docs for more information on sending data.

- serviceBus.authorizationHeaderValue: The signature is valid for 16 days. To renew the signature the device needs to call the DPS-registration endpoint again.

- api.baseUrl: The base address for the digital-twin api

- cloudSpaceUrl: The url that refers to the online dashboard of the device.