EntraID Security
Allowing our customers to sign in with their own organisational accounts not only conveniences them, but enhances the security of their portal. We should always encourage customers to take this route unless they have a specific requirement to use separate accounts for viewing gHost, from their work accounts.
In order to enable EntraID security, a few simple steps must be followed.
Microsoft Configuration
The following steps will need to be performed by an Administrator in the gHost business' Azure portal:
Add a 'redirect URI' for the customer's gHost domain, in the gHost application configuration

gHost Configuration
The following steps will need to be performed by an Administrator in the customer's gHost portal:
Enable the 'gHost Microsoft Authentication' feature
Navigate to the Configuration > Features page, and ensure the gHost Microsoft Authentication feature is enabled.

Enable the 'Users Registration' feature
On the same page, ensure the Users Registration feature is enabled.

Remove the 'view all content' permission from the 'Anonymous' user role
Navigate to the Security > Roles > Anonymous > Edit page, and ensure all checkboxes are unmarked.

Configure the 'Azure ActiveDirectory' plugin
Navigate to the Security > Authentication > Azure Active Directory page, and ensure the fields are set appropriately.
- The value for
AppIdis326d82e5-4477-4204-8b0a-a3cb85e6b8ab
Configure the 'User Registration' plugin
Navigate to the Security > Settings > User Registration page, and ensure no boxes are ticked on the 'Content' tab.
On the 'External Authentication' tab, ensure only the following checkboxes are marked:
- 'Do not ask username'
- 'Do not ask email address'
- 'Do not create local password'
- 'Use a script to generate userName based on external provider claims'
In the 'script box', please paste the following script; remove 'gtsgroup.com.au' if necessary; and update the 'CUSTOMER DOMAIN HERE' text as required:
var adminDomains = ["gtsgroup.com.au","ghost.site"];
var userDomains = ["CUSTOMER DOMAIN HERE"];
//Initialise necessary temporary variables for login script execution
var userEmail = "";
var validatedEmail;
var canRegister;
log("Warning", "-- user registration request --");
// Uncomment to map AzureAD
switch (context.loginProvider) {
case "AzureAd":
context.externalClaims.forEach(claim => {
if (claim.type === "http://schemas.microsoft.com/ws/2008/06/identity/claims/role") {
switch (claim.value) {
case "d8b59d62-9280-49ac-903a-2f02a581e067":
adminEmail = true;
break;
default:
break;
}
}
if (claim.type === "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress") {
if (adminDomains.includes(claim.value.split("@")[1])) {
userEmail = claim.value;
adminEmail = true;
}
else if (userDomains.includes(claim.value.split("@")[1])) {
userEmail = claim.value;
}
}
if (claim.type === "xms_edov") {
validatedEmail = claim.value;
}
});
break;
default:
log("Warning", "Provider " + context.loginProvider + " was not handled");
// Uncomment to generate a username as a uuid
// context.userName = "u" + uuid();
break;
}
if ((validatedEmail == "true" || validatedEmail == 1) && userEmail.length > 0) {
var userDomain = userEmail.split("@")[1];
var userName = userEmail.split("@")[0];
if (adminDomains.includes(userDomain) || userDomains.includes(userDomain)) {
canRegister = true;
} else {
log("Error", userEmail + " has attempted sign-up with an unallowed email domain");
}
} else {
log("Error", userEmail + " has attempted sign-up with an unvalidated or unallowed email domain");
}
if (canRegister) {
context.userName = userEmail.split("@")[0];
}
else {
context.userName = "~!@#$%^&*()_+=1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ";
}

Configure the 'User Login' plugin
Navigate to the Security > Settings > User Login page, and ensure only the following checkboxes are marked on the 'General' tab:
- 'Allow user to change their phone number'
- 'Use site theme for login page'
- 'Disable local password login' (if the customer does NOT want Basic authentication username/password)
Ensure only the following checkbox is marked on the 'External Login' tab:
- Use a script to set user roles, user claims and user properties based on external provider claims'
In the 'script box', please paste the following script; remove 'gtsgroup.com.au' if necessary; and update the 'CUSTOMER DOMAIN HERE' text as required:
var adminDomains = ["gtsgroup.com.au","ghost.site"];
var userDomains = ["CUSTOMER DOMAIN HERE"];
var currentRoles = context.userRoles;
//Initialise necessary temporary variables for login script execution
var userEmail = "";
var validatedEmail;
var adminEmail;
var userFirstName = "";
//log("Warning", JSON.stringify(currentRoles));
// Uncomment to map AzureAD
switch (context.loginProvider) {
case "AzureAd":
//log("Warning", JSON.stringify(context));
//log("Warning", JSON.stringify(context.userProperties?.gHostUserProfile.gHostUserProfile.UserShortName));
//log("Warning", context.userProperties?.gHostUserProfile != null);
context.externalClaims.forEach(claim => {
if (claim.type === "http://schemas.microsoft.com/ws/2008/06/identity/claims/role") {
switch (claim.value) {
case "d8b59d62-9280-49ac-903a-2f02a581e067":
adminEmail = true;
break;
default:
break;
}
}
if (claim.type === "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress") {
if (adminDomains.includes(claim.value.split("@")[1])) {
userEmail = claim.value;
adminEmail = true;
}
else if (userDomains.includes(claim.value.split("@")[1])) {
userEmail = claim.value;
}
}
if (claim.type === "xms_edov") {
validatedEmail = claim.value;
}
if (claim.type === "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname") {
userFirstName = claim.value;
}
});
if ((validatedEmail == "true" || validatedEmail == 1) && userEmail.length > 0) {
if (!currentRoles.includes("Authenticated")) {
log("Info", userEmail + " is a validated email address in the list of allowed sign-on domains, but is not yet an Authenticated user. Adding role to update list.");
context.rolesToAdd.push("Authenticated");
}
if (adminEmail && !currentRoles.includes("Administrator")) {
log("Info", userEmail + " is a validated email address in the list of allowed administrator domains, but is not yet an Administrator user. Adding role to update list.");
context.rolesToAdd.push("Administrator");
}
try {
if (userFirstName.length > 0 && context.userProperties?.gHostUserProfile != null && context.userProperties?.gHostUserProfile.gHostUserProfile.UserShortName != userFirstName) {
//log("Warning", JSON.stringify(context.userProperties));
context.propertiesToUpdate = {
gHostUserProfile: {
ContentType: "gHostUserProfile",
gHostUserProfile: {
UserShortName: {
Text: userFirstName
}
}
}
}
} else if (context.userProperties?.gHostUserProfile == null) {
//log("Info", userEmail + " does not have a user shortname set. Attempting to update profile here.");
context.propertiesToUpdate = {
gHostUserProfile: {
ContentType: "gHostUserProfile",
gHostUserProfile: {
UserShortName: {
Text: userFirstName
}
}
}
}
}
} catch (error) {
log("Error", "Unable to set a shortname on this user's user profile")
}
} else {
log("Error", userEmail + " has attempted sign-up with an unvalidated or unallowed email domain");
}
}
//Report on whether the user could successfully log in
var successfulLogin = (context.rolesToAdd.length + currentRoles.length > 0);
if (successfulLogin) {
log("Info", userEmail + " has logged in via " + context.loginProvider.toLowerCase());
} else {
log("Error", userEmail + " has unsuccessfully tried to log in via " + context.loginProvider.toLowerCase());
}
