Share devices within user groups

2 minutes read
Edit on GitHub

Devices are organized in the Identity Store service by the owner ID retrieved from the JWT token. The plgd API will be based on this value to identify the user and grant him the permissions only to devices he owns. By default, JWT claim sub is used as the owner ID. In case you connect the plgd authorization service with the Auth0, each logged-in user can access only his devices. This behaviour can be changed by changing the OWNER_CLAIM configuration property and adding custom claim to your Auth0 users.

  1. Go to Users & Roles

  2. Find your user and edit his details

  3. Extend the user_metadata by a custom claim, e.g.

    SOURCE Copy
    Copied
            {
        "tenant": "e3e0102d-a45b-5cb2-a22e-3a0410deb8d6"
    }
        
  1. Go to Applications
  2. Edit your Machine to Machine application
  3. Open Advanced Settings, switch to Application Metadata and add entry:
    • Key: tenant
    • Value: *
  1. Go to Rules and create new one

  2. Copy and paste the function below, which uses custom claim https://plgd.dev/tenant

    SOURCE Copy
    Copied
            function addTenantToAccessToken(user, context, callback) {
        var tenantClaim = 'https://plgd.dev/tenant';
        var tenant = (user && user.user_metadata && user.user_metadata.tenant) || (context && context.clientMetadata && context.clientMetadata.tenant) || null;
        if (tenant) {
            context.accessToken[tenantClaim] = tenant;
            context.idToken[tenantClaim] = tenant;
        }
        return callback(null, user, context);
    }
        

After the rule is created, Auth0 include into every access tokens custom claim https://plgd.dev/tenant used to group users and “their” devices. In case the custom OWNER_CLAIM is configured, devices are no more owned by a single user, but in this case, by the tenant. Each user who is a member of the tenant A will be able to access all the devices of this tenant.

Important

If the configuration property OWNER_CLAIM is changed, each user is required to have this claim present.

May 13, 2021

Get started

plgd makes it simpler to build a successful IoT initiative – to create a proof of concept, evaluate, optimize, and scale.

Get Started Illustration Get Started Illustration