New Azure AD connection logins fail until clicking Save in the Dashboard

Problem statement

We created a new Azure AD connection with the /api/v2/connections endpoint, and we are seeing logins fail and we are taken to a Microsoft login error page: 'Sorry, but we’re having trouble signing you in.' However, after hitting the Save button on the connection settings page in the Dashboard, logins are successful.

Solution

During the initial request to POST /api/v2/connections when you create the new connection, replace the options.domain property with the options.tenant_domain property and set it to the same value. This will allow logins to work without needing to go to the Dashboard UI and save the connection.