Core
IoT Backend v2.x
2

Setup your first tenant #

Now, we need to setup a tenant group so then we can create our first tenant and our first user.

But before all of this, let's create the Platform Admin user:

Copied to clipboard!
kourou security:createUser '{
  "content": {
    "profileIds": ["admin"],
  },
  "credentials": {
    "local": {
      "username": "platform-admin",
      "password": "password"
    }
  }
}'

Declare a new tenant group #

We need to declare a new tenant group in the backend by using the IoT Backend framework. Tenant group are declared by setting up profiles in the Multi-Tenancy plugin, in this example we will setup a smartcity tenant group.

You can see an example of this in the apps/api/lib/modules/permissions/PermissionsModule.ts file

We will use the multiTenancy.registerProfilesTemplates method to register our profiles:

Copied to clipboard!
import { ProfileTenantAdmin, ProfileTenantReader } from "@kuzzleio/iot-backend";
import { MultiTenancyPlugin } from "@kuzzleio/plugin-multi-tenancy";

// Retrieve the plugin from the application instance
const multiTenancy = app.plugin.get < MultiTenancyPlugin > "multi-tenancy";

// Register profiles for the "smartcity" tenant group
multiTenancy.registerProfilesTemplates("air_quality", {
  [ProfileTenantAdmin.name]: ProfileTenantAdmin.definition,
  [ProfileTenantReader.name]: ProfileTenantReader.definition,
});

ProfileTenantAdmin and ProfileTenantReader are predefined profiles available through the @kuzzleio/iot-backend package.

Create a tenant #

Now, we can create a tenant of type smartcity.

You can login to the IoT Console and navigate to Admin > Tenants to create a new tenant:

  • Screenshots

    create tenant

Or you can use the command line:

Copied to clipboard!
kourou multi-tenancy/tenant:create -a name="buenos_aires" -a group="air_quality"

Create an user #

Once we have a tenant, we can create users inside it. Those users will be strictly restricted to their tenant data.

We will create an admin user for the tenant, the admin user will then be capable of creating new users by himself.

Still loggued in as the Platform Admin, you can navigate to Admin > Users to create a new user for the tenant:

  • Screenshots

    create user

    create user

Or you can use the command line:

Copied to clipboard!
kourou multi-tenancy/user:create -a tenantId=tenant-hyvision-buenos_aires -a profile=admin --username platform-admin --password password

Now, you can login to the IoT Platform as your tenant user.