Skip to main content

Let customers manage their own members

Give the administrators of a customer a portal in which they invite people and assign roles, with no work for your team.

RecipeDraftView source
This page is a draft. The code exists, and not all of it has been run for this page yet. The page says what was checked.
Works with
Plain HTTP

What it shows​

  1. You choose which people the administrators of a customer may invite: only people with an account, or any address.
  2. Your product links to the portal of the customer, at /b2b/{orgId}/{slug}/.
  3. An owner or administrator of the customer invites a colleague there, and gives them a role.
  4. LumoAuth sends a webhook event for each change, so that your app can update its own records.

Before you start​

  • A customer organization with one owner or administrator. One organization for each customer creates Northwind Labs with an owner.
  • Check that your plan includes self-service for customer organizations in the plans matrix. Without it the portal shows its pages, and offers no form for invitations or role changes.
  • An API key with the scopes admin:settings:read, admin:settings:write and admin:users:read. The script needs jq.
VariableValue
LUMOAUTH_URLThe address of LumoAuth: https://app.lumoauth.dev, or https://eu.app.lumoauth.dev for the EU region.
LUMOAUTH_ORG_IDYour organization, for example acme-corp.
LUMOAUTH_API_KEYAn API key with the scopes admin:settings:read, admin:settings:write and admin:users:read. Its creator needs the permission settings.manage.
CUSTOMER_SLUGOptional. The slug of the customer organization. The default is northwind-labs.

Code​

Run each command from the recipes folder of the examples repository. Set the folder up once for your language. Every version below was run against a LumoAuth organization. The script and the portal steps were run: an owner invited a new person, the person joined, and the owner changed the role. The webhook events were not seen, because the test organization delivered no webhooks.

b2b/customer-admin-portal/http/portal.sh
#!/bin/sh
# Let the administrators of your customers invite people who have no account
# yet, and print the address of the portal of one customer, with curl and jq.
#
# sh b2b/customer-admin-portal/http/portal.sh
set -eu

SLUG="${CUSTOMER_SLUG:-northwind-labs}"
ORGANIZATION="$LUMOAUTH_URL/orgs/$LUMOAUTH_ORG_ID/api/v1/admin/organization"

# Without this setting a customer administrator can invite only people who
# have an account in your organization already. `settings` is merged one key
# at a time, so the other settings stay as they are.
curl --silent --show-error --request PATCH "$ORGANIZATION" \
--header "X-API-Key: $LUMOAUTH_API_KEY" \
--header "Content-Type: application/json" \
--data '{"settings": {"b2b_org_admins_may_invite_new_accounts": true}}' > /dev/null

ALLOWED=$(curl --silent --show-error "$ORGANIZATION" --header "X-API-Key: $LUMOAUTH_API_KEY" \
| jq .data.settings.b2b_org_admins_may_invite_new_accounts)
echo "customer administrators may invite people with no account: $ALLOWED"

# Each customer organization has its own portal. Put this link on the page
# "Manage team" of your product.
MEMBERS=$(curl --silent --show-error "${ORGANIZATION}s/$SLUG" --header "X-API-Key: $LUMOAUTH_API_KEY" \
| jq .data.memberCount)
echo "members of $SLUG: $MEMBERS"
echo "portal: $LUMOAUTH_URL/b2b/$LUMOAUTH_ORG_ID/$SLUG/"
sh b2b/customer-admin-portal/http/portal.sh

The same switch is in the portal: open Identity, Customer organizations, and look for Customer portal invitations at the bottom of the page.

Then the customer does the rest. Sign in as the owner of Northwind Labs and follow these steps:

  1. Open the address that the script printed. The sidebar shows Dashboard, Your access, Members, Invitations, Roles, Applications, Agents and Settings.
  2. Open Invitations. Under Send an invitation, enter the Email of the colleague, choose a Role, and click Send invitation. The page answers "Invitation sent."
  3. The colleague opens the link of the email, creates an account, and arrives in the portal as a member.
  4. Open Members. In the row of the colleague, choose another role in the Role list. The page answers "Role updated."

Check the result​

Output
customer administrators may invite people with no account: true
members of northwind-labs: 1
portal: https://app.lumoauth.dev/b2b/acme-corp/northwind-labs/
  • A member with the role Member sees the portal with fewer pages: Invitations and Settings are missing. The address of the invitations page answers "This page is for Northwind Labs administrators".
  • A member cannot change their own role: their own row on Members has no list.
  • In your portal, the Members tab of the customer organization shows the new member and the role.

Your app learns about each change from the webhook events organization.invitation.accepted, organization.member.added, organization.member.updated and organization.member.removed. Receive webhooks shows the handler. While you develop, the CLI forwards the events to your machine:

lumo tunnel --to http://localhost:3000/webhooks --filter organization.member.added --filter organization.member.updated

Limits​

  • The setting applies to all your customer organizations. You cannot turn it on for one customer only.
  • With the setting off, an invitation to an address without an account sends no email. The form gives the same answer for every address, so an administrator cannot find out who has an account.
  • Only an owner can change the slug of the organization or deactivate it.
  • A person who is not signed in gets the sign-in page first. Link to the portal from a page of your product that people see after sign-in.