Within Auth0, there is the option to have a different login experience for different companies, this is only possible through organizations. Then we still won't be able to have multiple subdomains..., (organizations). Using organizations is only possible when you're not using the Auth0 management API. Which we are using. Therefore, the solution to create a SaaS product, with multiple subdomains, where companies can log in over their MS AAD tenant on their own subdomain is as follows:
- I've created a multiple AAD tenant application.
- I've created one Auth0 tenant per subdomain.
- Every single Auth0 tenant will be connected to our own multiple AAD tenant application
- Within every single Auth0 tenant, you can add rules (in the future actions), in here we can check if the user trying to log in has a matching tenant ID with the allowed tenant ID's. If the user's tenant ID is from a different company, it won't be on our whitelist.
The rules within the auth0 pipeline look like this for now.
function (user, context, callback) {
var ownAADTenantID = 'lotsofnumbersandletters';
var companyAADTenantID = 'lotsofnumbersandletters';
//authorized Azure AD tenants.
var whitelist = [ ownAADTenantID, companyAADTenantID ];
var userHasAccess = whitelist.some(
function (tenantId) {
return tenantId === user.tenantid;
});
if (!userHasAccess) {
return callback(new UnauthorizedError('Access denied.'));
}
return callback(null, user, context);
}
- The rules will be depreciated in November 2024, I hope Auth0 will have a solution to use the actions by then....