MS Entra Integration
This directory contains scripts for integrating with Microsoft Entra ID (formerly Azure Active Directory), including domain federation setup.
Domain Federation Setup
The create-domain-federation.ps1
script automates the process of:
- Creating a custom domain in Microsoft Entra ID
- Verifying domain ownership via DNS records
- Setting up SAML federation for the domain
Prerequisites
- PowerShell Core (pwsh) 7.0 or higher
- Microsoft Graph PowerShell module installed
- Appropriate permissions in Microsoft Entra ID
To install the required PowerShell module:
Install-Module Microsoft.Graph -Scope CurrentUser
Configuration
Before running the script, you need to create a configuration file for your environment:
-
Create a configuration file named
config.<environment>.ps1
in theenv
directory:touch backend/identity/iam/ms-entra/env/config.<environment>.ps1
-
Add the following content to your configuration file, replacing the values with your own:
# Microsoft Entra ID tenant ID
$TenantId = "your-tenant-id"
# Domain to create and federate
$DomainName = "yourdomain.com"
# Base64-encoded X.509 certificate for SAML signing
$SigningCertificate = "MIIDXTCCAkWgAwIBAgI..."
Notes:
- TenantId can be found in MS Entra admin console: https://entra.microsoft.com/#settings/directory, and select the directory id of the user directory you want to federate.
- DomainName should be the domain for which you define users (e.g. your.user@yourdomain.com)
- Vouch Identity must be hosted such that https://sso.yourdomain.com serves the backend
Running the Script
To run the script:
# Run the script with your environment configuration
./create-domain-federation.ps1 -Environment <environment>
The script will:
- Connect to Microsoft Graph API
- Check if the domain exists
- Create the domain if it doesn't exist
- Verify domain ownership (requires DNS record creation)
- Set up or update federation configuration
- Configure sign-in auto-acceleration for applications
Auto-Acceleration
The script automatically configures sign-in auto-acceleration, which allows users to skip the Microsoft Entra sign-in page and go directly to your federated identity provider's sign-in page. This improves the user experience for federated authentication.
By default, the script will:
- Create a Home Realm Discovery policy for auto-acceleration
- Apply it to applications tagged with "VouchFederated"
- If no tagged applications are found, apply it to common Microsoft 365 applications
To tag an application for auto-acceleration:
# Get the service principal ID of your application
$appId = "your-application-id"
# Add the VouchFederated tag
Update-MgServicePrincipal -ServicePrincipalId $appId -Tags @("VouchFederated")
Domain Verification
When the script prompts for domain verification:
- Create the TXT DNS record shown in the output
- Wait for DNS propagation
- Confirm when the record is created
- The script will attempt to verify the domain
Troubleshooting
Incorrect issuer / sign uri
If your environment configuration has an incorrect setup, i.e. the issuer / sign uri aren't matching the domain, you might encounter the following (totally irrelevant) error:
New-MgDomainFederationConfiguration_CreateExpanded: /home/stijn/Documents/code/vouch/vouch/backend/identity/iam/ms-entra/create-domain-federation.ps1:123
Line |
123 | New-MgDomainFederationConfiguration `
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Domain already has Federation Configuration set. Status: 400 (BadRequest) ErrorCode: Request_BadRequest Date: 2025-04-01T09:52:50 Headers: Cache-Control : no-cache Vary : Accept-Encoding
| Strict-Transport-Security : max-age=31536000 request-id : 32856efe-22b0-4540-9de4-c33d7e3e8377 client-request-id : b282bd9c-516a-4692-a59c-5afb87b85863 x-ms-ags-diagnostic : {"ServerInfo":{"DataCenter":"West
| Europe","Slice":"E","Ring":"5","ScaleUnit":"001","RoleInstance":"AM4PEPF00033F3A"}} x-ms-resource-unit : 1 Date : Tue, 01 Apr 2025 09:52:49 GM
In order to fix this problem, you have to:
- Update your configuration to align the domain and issuer / sign uri
- Remove the existing domain from MS Entra:
a. You can do this either in the MS Entra Admin console: https://entra.microsoft.com/#view/Microsoft_AAD_IAM/DomainsManagementMenuBlade/~/CustomDomainNames
b. Or with PowerShell:
Remove-MgDomain -Id <your-domain>
- Re-run the script (and perform domain verification again)
Authentication Issues
If you encounter authentication issues:
- Ensure you have the correct permissions in Microsoft Entra ID
- Try running
Connect-MgGraph
manually to troubleshoot authentication - Check that your tenant ID is correct in the configuration file