Prerequisites
Before you can configure custom provisioning, you must:- Configure Office 365: Register a and configure Office 365 as a third-party application in Auth0.
Configure Azure AD
Custom provisioning uses the Azure AD Graph API to provision new users in Azure AD. To access the Azure AD Graph API, you must create an application within the Azure AD Directory that has been linked to the Office 365 subscription:- Log in to the Azure Portal.
- Choose Azure Active Directory in the left navigation.
- Select App registrations in the new menu.
- Click on New application registration.
-
Fill the form:
- Input a name for the application (such as
Auth0 Provisioning
) - Select Web app / API as the Application type.
- Insert a sign-on URL. You can enter any valid URL; this won’t really be used.
- Input a name for the application (such as
- The recently-created app will appear in the App registrations list. Select it.
- In the Settings blade (Microsoft call these sections “blades”), choose Keys.
-
Input a Description (like
Auth0 Provision
), and choose a Duration for the new key. If you choose to issue a non-permanent key, take note of the expiration date and create a reminder to replace the key with a new one before it expires. - Click to save the key, then copy the App Key. This key will be shown only once, and it’s needed for the Auth0 rule.
- Choose Required permissions, and click Add in the new blade.
-
Select the Microsoft Graph API, then check
Read and write directory data
under Application Permissions. - Back in the Required permissions, click on the Grant Permissions button, and then click Yes to grant the requested permissions.
Create the Azure AD provisioning rule
The following rule shows the provisioning process:- If the user comes from the AD connection, skip the provisioning process (because this will be handled by DirSync).
- If the user was already provisioned in Azure AD, just continue with the login transaction.
- Use the Azure AD Client ID and Key to get an Access Token for the Graph API.
- Create a user in Azure AD.
- Assign a license to the user.
- Continue with the login transaction.
createAzureADUser
function, which by default, generates a username in the format auth0-c3fb6eec-3afd-4d52-8e0a-d9f357dd19ab@fabrikamcorp.be
. You can change this to whatever you like; just make sure this value is unique for all your users.
Make sure you set the correct values for the AUTH0_OFFICE365_CLIENT_ID
, AAD_CUSTOM_DOMAIN
, AAD_DOMAIN
, AAD_APPLICATION_ID
and AAD_APPLICATION_API_KEY
values in your configuration object to make the values available in your rule code. To learn more, read Store Configuration for Rules.
In the code, you’ll also see that the rule will wait about 15 seconds after the user is provisioned. This is because it takes a few seconds before the provisioned user is available for Office 365.
This code shows the provisioning process of a new user, but you can also adapt the code to synchronize metadata of existing users.
User experience
The easiest way for your external users to authenticate is by using Identity Provider-initiated login. You must redirect your users to the following URL (e.g., using a “smart link” likehttps://office.travel0.com
):
Deep linking
Certain implementations might require deep linking (for example, to SharePoint Online). In this case, a smart link needs to be constructed, which starts on the Office 365 login page:{yourCustomDomain}
, should be the domain you’ve configured in Azure AD for (e.g., travel0.com
). By specifying this as the whr
, Azure AD will know it needs to redirect to Auth0 instead of showing the login page.
The DEEP_LINK
parameter should be an encoded URL within Office 365 (for example, a page in SharePoint Online or Exchange).
Example URL: