Based on your description, you're encountering the AADSTS90019 error when trying to set up Keycloak as a SAML identity provider for SharePoint Online. Here's how to resolve this:
Key Requirements for Direct Federation
- Tenant Identification: The error indicates Azure AD can't determine which tenant to authenticate against. You need to explicitly specify your Azure AD tenant in the authentication request.
- Correct Configuration: You're on the right track using the direct federation approach, but there are some missing pieces.
Solution Steps
For your Keycloak SAML client configuration:
- Entity ID: Must match exactly what you registered in Azure AD
- NameID Format:
urn:oasis:names:tc:SAML:2.0:nameid-format:persistent
- Assertion Consumer Service URL:
https://login.microsoftonline.com/login.srf
- Add Required Claims:
-
http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress
(maps to user email)
-
http://schemas.microsoft.com/identity/claims/tenantid
(your Azure AD tenant ID)
2. Azure AD Configuration
You need to configure Azure AD to accept your Keycloak as a direct federation provider:
# PowerShell example to configure direct federation
New-MgDomainFederationConfiguration -DomainId yourdomain.com -ActiveSignInUri "https://your-keycloak/auth/realms/your-realm/protocol/saml" -IssuerUri "https://your-keycloak/auth/realms/your-realm" -MetadataExchangeUri "https://your-keycloak/auth/realms/your-realm/protocol/saml/descriptor" -SigningCertificate "YourBase64EncodedCertificate"
3. Required Attributes
Ensure your SAML response includes:
-
IDPEmail
(must match user's UPN in Azure AD)
- Tenant identifier (either as
tenantid
claim or in the Issuer
URL)
4. Application Registration (Optional but Recommended)
While direct federation should work, registering an enterprise application in Azure AD can provide better control:
- Go to Azure AD > Enterprise Applications
- Create a new SAML-based application
- Configure the SAML settings to point to your Keycloak instance
Troubleshooting Tips
- Verify your Azure AD tenant ID is correctly included in requests
- Check the Issuer URL in your SAML response matches what's configured in Azure AD
- Use SAML tracer to examine the exact SAML response being sent
- Ensure clock synchronization between Keycloak and Azure AD
Alternative Approach
If you continue having issues, consider using:
- Azure AD B2B with Keycloak as an external identity provider
- SAML/WS-Fed identity provider federation through Azure AD External Identities