Skip to main content

Advanced Example Using the Auth API (Tenant Attribute)

This advanced example constructs an email address from a tenant-specific username and tenant ID using a tenant attribute.
If each tenant has a different login_domain, usernames need only be unique within each tenant, so different tenants can use the same username.
The sample's standard login accepts an email address or SaaSus Platform login ID directly.
This example is separate from the direct login-ID flow.

See Basic implementation using the Auth API for the basic authentication flow.

Prerequisites​

  • Define the string tenant attribute login_domain and set a value such as @example.com for each tenant.
  • Register users with the email address formed by joining the username and login_domain.

For example, username taro and login_domain @example.com authenticate the user registered as taro@example.com.
Enter the tenant ID on the login screen or supply it in the login URL as ?tenant_id=....

Sign-in flow​

  1. The frontend sends the username, tenant ID, and browser-generated SRP public value to the sample backend's /challenge-id endpoint.
  2. The backend retrieves login_domain with GetTenant and joins it to the username.
  3. The backend calls SignIn with the resulting email address and public value, then returns the challenge to the frontend.
  4. As in standard sign-in, the frontend generates a signature and sends it to /verify.
const response = await apiClient.post('/challenge-id', {
user_id: userId,
tenant_id: tenantId,
srp_a: srpA,
});

/challenge-id is an endpoint in the sample backend.
The password is used for SRP calculation in the browser and is not sent to the backend during normal sign-in.