website/integrations/platforms/microsoft/index.md
Microsoft 365 is the cloud productivity platform that delivers Office applications, Teams collaboration, and identity services from Microsoft's global infrastructure.
The following placeholders are used in this guide:
authentik.company is the FQDN of the authentik installation.domain.company is the custom domain federated with Microsoft Entra ID.:::info This documentation lists only the settings that you need to change from their default values. Be aware that any changes other than those explicitly mentioned in this guide could cause issues accessing your application. :::
To support the integration of Microsoft365 with authentik, you need to:
Microsoft Entra ID requires a unique and immutable identifier (called ImmutableId or sourceAnchor) for each user during SAML federation. This identifier is sent as the SAML NameID attribute and must match the ImmutableId value configured in Entra for each user.
If you are using an Active Directory source in authentik, the immutable identifier is typically the base64-encoded objectGUID from Active Directory. You will need to create a property mapping on your Active Directory source in authentik that stores this value in a custom user attribute, for example: entra_immutable_id.
If your users aren't synchronized from Active Directory and only exist in authentik, you can use any unique and stable identifier such as the user's UUID or email address. You will also need to configure the ImmutableId in Entra ID to match the identifier that authentik sends.
ImmutableIdLog in to authentik as an administrator and open the authentik Admin interface.
Navigate to Customization > Property Mappings and click Create.
Select type: select SAML Provider Property Mapping.
Configure the SAML Provider Property Mapping: provide a descriptive name (e.g. Microsoft Entra Immutable ID), and, optionally a friendly name.
http://schemas.microsoft.com/claims/multipleauthn# For users synchronized from Active Directory with the 'entra_immutable_id' attribute.
# Replace 'entra_immutable_id' with whatever you set this attribute's name to.
return user.attributes.get("entra_immutable_id", "")
# OR for cloud-only users with email address as their immutable ID
# return user.email
Click Finish to save the property mapping.
If MFA is configured in Microsoft365, then you also need to create a property mapping for AuthnContextClassRef, otherwise the user will be prompted for credentials twice.
AuthnContextClassRefLog in to authentik as an administrator and open the authentik Admin interface.
Navigate to Customization > Property Mappings and click Create.
Select type: select SAML Provider Property Mapping.
Configure the SAML Provider Property Mapping: provide a descriptive name (e.g. Microsoft Entra AuthnContextClassRef), and, optionally a friendly name.
AuthnContextClassRefreturn "http://schemas.microsoft.com/claims/multipleauthn"
Click Finish to save the property mapping.
Log in to authentik as an administrator and open the authentik Admin interface.
Navigate to Applications > Applications and click Create with Provider to create an application and provider pair. (Alternatively you can first create a provider separately, then create the application and connect it with the provider.)
https://login.microsoftonline.com/login.srf.https://authentik.company/application/saml/<application_slug>/metadata/.Post.urn:federation:MicrosoftOnline.authentik default SAML Mapping: Email.AuthnContextClassRef property mapping that you created in the previous section.Click Submit to save the new application and provider.
.pem to .cer.You must use the Microsoft Graph PowerShell module to federate your Microsoft Entra domain with authentik. The module can be installed by running the following PowerShell command:
Install-Module Microsoft.Graph -Scope CurrentUser
ImmutableId valuesBefore configuring federation, you need to set the ImmutableId for each user in Entra ID to match the identifier that authentik will send.
If you're synchronizing users from Active Directory to authentik, the ImmutableId should already be set by Microsoft Entra Connect (typically from the objectGUID). Verify this is configured correctly before proceeding with federation.
If your users aren't synchronized from Active Directory and only exist in authentik, run the following PowerShell commands:
# 1. Connect to Microsoft Graph
Connect-MgGraph -Scopes "User.ReadWrite.All"
# 2. Set ImmutableId for all users in the domain
$users = Get-MgUser -Filter "endsWith(mail,'@domain.company')" -All
foreach ($user in $users) {
if ($user.Mail) {
Update-MgUser -UserId $user.Id -OnPremisesImmutableId $user.Mail
Write-Host "Set ImmutableId for $($user.Mail)"
}
}
Run the following PowerShell commands to configure the federation between Microsoft Entra ID and authentik.
:::info Domain Verification Domain creation and DNS verification are outside the scope of this guide. Ensure your custom domain is already added and verified in Microsoft Entra ID before proceeding with this guide. :::
# 1. Connect to Microsoft Graph
Connect-MgGraph -Scopes "Domain.ReadWrite.All", "Directory.AccessAsUser.All", "User.Read.All", "Application.ReadWrite.All"
# 2. Define all variables
$domain = "domain.company"
$PassiveLogOnUri = "https://authentik.company/application/saml/<application_slug>/sso/binding/post/"
$LogOffUri = "https://authentik.company/application/saml/<application_slug>/slo/binding/post/"
$IssuerUri = "https://authentik.company/application/saml/<application_slug>/metadata/"
$MetadataExchangeUri = $IssuerUri
$ActiveSignInUri = "https://authentik.company/application/saml/<application_slug>/sso/binding/post"
$SigningCert = Get-Content "C:\path\to\authentik_certificate.cer" -Raw
$DisplayName = $domain
$FederatedIdpMfaBehavior = "acceptIfMfaDoneByFederatedIdp"
# 3. Configure the federation
# Note: The backtick (`) at the end of each line is PowerShell's line continuation character. Make sure to not remove this character when copying the command below.
New-MgDomainFederationConfiguration `
-DomainId $domain `
-PassiveSignInUri $PassiveLogOnUri `
-SignOutUri $LogOffUri `
-IssuerUri $IssuerUri `
-MetadataExchangeUri $MetadataExchangeUri `
-SigningCertificate $SigningCert `
-DisplayName $DisplayName `
-FederatedIdpMfaBehavior $FederatedIdpMfaBehavior `
-PreferredAuthenticationProtocol "saml" `
-ActiveSignInUri $ActiveSignInUri
To confirm that authentik is properly configured with Microsoft365, log out of your Microsoft account, then attempt to log back in by visiting Microsoft 365 Portal and clicking Sign In. Enter an email address in your federated domain, then click Next. You should be redirected to authentik and, once authenticated, redirected back to Microsoft and logged in.