How Keycloak brokers AD FS sign-in over SAML 2.0
The integration uses Keycloak's SAML 2.0 identity provider support, with AD FS acting as the SAML identity provider and Keycloak acting as the service provider. Your workforce signs in once through AD FS, Keycloak receives a SAML assertion from it, and Keycloak then issues its own OpenID Connect or SAML tokens to the downstream applications behind it. Those applications never talk to AD FS directly, so Keycloak becomes the single place where sign-in policy, session handling and claim mapping are configured.
This is identity brokering, not user federation. Keycloak does not read accounts out of Active Directory or check passwords against a directory. Each user is authenticated by AD FS, and Keycloak creates or links a local user record from the assertion on first login. The consequence is that user existence, password policy, account lockout and group membership remain governed by the directory, and Keycloak only sees what AD FS chooses to assert. If a user is disabled in Active Directory Domain Services but still holds a Keycloak session, the session lifetime you set in Keycloak decides how long access continues, so confirm that value with your security team before go-live.
AD FS runs on Windows Server, and the accounts it authenticates sit in Active Directory Domain Services on domain controllers in your environment. Confirm which Windows Server release and AD FS version your federation servers run, since support windows differ by release, and confirm which claim rules your AD FS administrators already publish to other relying parties. Those existing rules determine the NameID format and attributes Keycloak receives, so review them with the AD FS team before you write any Keycloak mapper.
What you need before AD FS can trust Keycloak
Brokering sign-in to AD FS depends on a few components being in place before any SAML configuration starts. Each card below is a decision or check that, if skipped, usually surfaces later as a failed trust, a certificate error or a login loop.
A confirmed AD FS farm
Record the AD FS version, the federation service name (the host name that appears in the federation metadata URL) and whether the farm is a single server or a load-balanced farm. Keycloak will fetch metadata from that name, so it must resolve and be reachable from the Keycloak network. Confirm the AD FS version and its SAML 2.0 support details in Microsoft's AD FS documentation rather than assuming them, because feature availability differs between AD FS releases.
A supported Keycloak release and database
Use a current, supported Keycloak release and a production database from the supported list, not the development file database. Plan the upgrade path before the trust is built, since a later Keycloak upgrade can change defaults that affect SAML handling. Confirm the exact database version against the Keycloak database guide for the release you deploy.
- Current release
- 26.8.1
TLS certificates on both sides
Keycloak needs a valid TLS certificate on its public hostname, and AD FS needs a certificate on its service name that clients trust. Keycloak's production guidance calls for TLS on all communication. Check certificate chains, expiry dates and whether your internal certificate authority is trusted by the Keycloak host, because a broken chain during metadata retrieval is a common first failure.
Network paths between three parties
Map the routes between users' browsers, the Keycloak public hostname, and the AD FS federation service. Users must reach both Keycloak and AD FS for the redirect and sign-in flow, and Keycloak's server must reach the AD FS metadata endpoint. Firewalls, reverse proxies and split DNS are the usual sources of trouble, so test each path with the same host names your users will use.
A supported Windows Server lifecycle
Confirm which Windows Server release hosts AD FS and check its support dates before you build on it. Windows Server 2022 mainstream support ended on October 14, 2026, and its extended support ends on October 15, 2031. Windows Server 2025 mainstream support ends on November 14, 2029, and extended support ends on November 15, 2034. Plan the operating system choice against your organization's support policy.
Windows Server 2025 lifecycleAdmin accounts on each side
Name one administrator for Keycloak, who can create identity providers, mappers and clients in the target realm, and one for AD FS, who can edit relying party trusts and claim rules. Keep these accounts separate from daily user accounts. Agree in advance who approves changes to signing certificates and claim rules, since both affect who can sign in.
How a SAML sign-in flows from Keycloak to AD FS and back
The sign-in starts when the user opens a client application that redirects to Keycloak, which in turn sends a SAML AuthnRequest to AD FS through the user's browser. AD FS authenticates the user against Active Directory on the corporate side of the trust boundary, then returns a signed SAML response to Keycloak's broker endpoint on the public hostname. Keycloak validates the signature and assertion, creates or links the local user using the chosen NameID, and issues its own token to the application. Check signing, audience, and NameID handling at the Keycloak hand-off, since that is where most brokering faults appear.
Sequence of a brokered SAML login from the client application through AD FS and back to Keycloak.
Configuring the AD FS relying party trust and the Keycloak provider in sequence
This sequence connects Keycloak and AD FS in both directions, so that AD FS issues SAML assertions for the Keycloak broker endpoint and Keycloak accepts them as a federated sign-in. Each step ends with a check that shows the trust is working before the next step begins.
Confirm the Keycloak service provider metadata and broker endpoint
The Keycloak administrator confirms the realm name, the hostname that users reach Keycloak on, and the SAML service provider metadata that Keycloak publishes for the realm. Keycloak's identity brokering model means AD FS will send its assertions to the realm's broker endpoint, so the realm's public frontend URL must be correct before anything else is configured. Record the exact entity ID and the assertion consumer service URL that the metadata lists. Check that the metadata document opens in a browser over TLS and that the entity ID and endpoint match the hostname users will actually use. The field names and metadata paths change between releases, so verify them against your Keycloak version using the Keycloak server administration guide.
Create the relying party trust in AD FS
An AD FS administrator creates a relying party trust in the AD FS management console and imports the Keycloak service provider metadata, either from the URL or from a saved file. The import fills in the relying party identifier and the assertion consumer endpoint. Confirm that the endpoint type is set to SAML 2.0 POST and that the identifier matches the Keycloak entity ID exactly, because a mismatch is the most common reason an AD FS sign-in fails early. Check that the trust appears in the relying party trust list with the expected identifier and endpoint before moving on to claim rules.
Write the claim issuance rules for NameID and attributes
The AD FS administrator adds issuance transform rules that send a NameID and the attributes Keycloak needs, such as the user principal name or email address, the display name and any group membership used for role mapping. Choose the NameID format deliberately, since Keycloak's identity provider settings must match it, and document the choice so that later changes do not break existing linked accounts. Decide which Active Directory attribute becomes the stable identifier, because changing it later can create duplicate accounts. Check the rule set by reviewing the claim rules in AD FS and confirming that the issuance order and claim types are what you intended. A test sign-in in a later step will confirm the values arrive as expected.
Add the AD FS metadata as a SAML identity provider in Keycloak
The AD FS administrator exports the federation metadata document from the AD FS service, and the Keycloak administrator adds a SAML v2.0 identity provider in the target realm using that document. Keycloak reads the signing certificate and the single sign-on endpoint from the metadata, so confirm the certificate that appears matches the token-signing certificate currently published by AD FS. Note the alias you assign, because it becomes part of the broker callback URL and any kc_idp_hint values. Check that the provider appears in the realm's identity provider list with the expected endpoint and certificate, and that the redirect URI shown by Keycloak matches the one registered in the AD FS trust.
Align signature and NameID options on both sides
Set the signature and NameID options in the Keycloak identity provider so they match the AD FS trust. Decide whether AD FS signs the assertion, the response or both, and whether Keycloak signs its authentication requests, then configure the same expectations on each side. Keycloak must use the same NameID format that the claim rules send, and the expected signing algorithm must match what AD FS produces. Mismatched signature requirements usually appear as validation errors in the server log rather than as a clear message in the browser, so record every option you set. Check the configuration by saving the provider and confirming in the Keycloak admin console that the saved values match your written trust specification.
Test with one account and inspect the SAML response
Use a single test account from the Active Directory domain that AD FS serves, and sign in through the Keycloak login page using the AD FS provider. Before the test, open the browser developer tools or a trace tool so the SAML response posted to Keycloak can be inspected, and confirm that AD FS returns the expected NameID and attributes. After a successful sign-in, check the realm's user list for a new federated user with the expected username and email, and confirm that the identity provider link appears on that user's record. If the sign-in fails, check the Keycloak server log and the AD FS event log for the same timestamp before changing any setting. Only expand the test to other accounts once the attributes and linked user look correct.
Choosing NameID and signing settings that match both sides
The decisions that cause most rework in an AD FS to Keycloak SAML setup are the NameID claim, the NameID format, whether AuthnRequests are signed, and whether assertions are encrypted. Each one must be set on the AD FS relying party trust and on the Keycloak SAML identity provider at the same time, because a mismatch on any of them usually fails at the first test with an unhelpful error. Before anyone opens either console, record the chosen values in a shared configuration sheet that both the AD FS administrators and the Keycloak team can read, and list the Keycloak keys that correspond to each setting so that a reviewer can check both sides against one document.
The NameID claim should be an identifier that will not change for the life of the account. The user principal name is common because it is what users type at sign-in, but it can change when a person is renamed or moves domains, and email addresses change in the same way. Keycloak links a federated login to a local user through the identity provider link, so an unstable NameID means accounts get orphaned or duplicated later. Decide early which value serves as the stable key, confirm with the directory owners how often it changes, and make sure the NameID format configured in Keycloak, such as persistent or an email format, matches what AD FS actually sends. Test with a real account whose identifiers you can verify rather than assuming the default.
Signing is where teams most often lose time. Decide whether Keycloak signs AuthnRequests, whether AD FS requires that, and which certificate signs assertions. Confirm the signing certificate's validity period and the rotation procedure with the AD FS owners before go-live, because a rotated certificate that is not imported into Keycloak will break sign-in without any change on the Keycloak side. Decide whether assertions must be encrypted, which requires a separate encryption certificate on the Keycloak side. Confirm these choices against your own AD FS version and your organization's policy, since the supported options depend on the environment, and rerun the test after each change on either side.
Mapping AD FS claims to Keycloak users and roles
This table pairs each common AD FS claim with its Keycloak target, the mapper type to confirm in your installed version, and how it behaves on each login. Read it as a starting design: confirm mapper names and sync modes in the Keycloak identity provider mapper documentation for your release before you build. The main takeaway is that the identifier and group decisions matter most, because they control account matching and who receives access.
| AD FS claim or attribute | Keycloak target | Mapper type and sync behavior |
|---|---|---|
| UPN or email as the identifier | Username and email on the Keycloak user | Confirm the username and email mapper types in the mapper documentation. Decide which claim is the NameID or identifier, since changing it later can create duplicate accounts. |
| Given name | First name | Attribute-to-user-property mapper, typically set to update on each login so HR changes reach Keycloak. Confirm the sync mode option for your version. |
| Surname | Last name | Attribute-to-user-property mapper, typically set to update on each login. Confirm the sync mode option for your version. |
| Group membership claims | Keycloak groups or realm and client roles | Claim-based role or group mapper. Test with a nested AD group, since the claim may carry only direct memberships. Sync mode determines whether removed groups are dropped at next login. |
| Department or cost-center attribute | Keycloak user attribute (not a role) | Attribute mapper that writes a custom user attribute. Use it for reporting or policy inputs, and confirm whether the claim is issued by your AD FS claim rule set before relying on it. |
| First-login account linking with an existing local or federated account | Existing Keycloak user matched on verified email or username | First broker login flow behavior. Confirm which review or linking step applies and whether email matching is trusted only for verified addresses in your version. |
Signing, encryption and admin hardening for the AD FS link
The AD FS link is only as trustworthy as the certificates, signatures and access paths behind it. These cards cover the controls that keep a SAML trust between AD FS and Keycloak verifiable, rotatable and limited to the users you intend to admit.
Validate signatures with pinned certificates
Keycloak should accept SAML responses and assertions only when they are signed by the AD FS token-signing certificate you have pinned from the agreed metadata, not whatever certificate a metadata refresh presents. Check that the identity provider configuration requires signature validation on both the response and the assertion, then send a test login with a deliberately altered or unsigned assertion in a non-production realm and confirm it is rejected.
Keycloak docsPlan certificate rotation on both sides
AD FS token-signing certificates and any Keycloak signing or encryption keys expire on their own schedules, and a lapse breaks sign-in for every user at once. Record each certificate's expiry date, agree who rotates each side and in what order, and rehearse the change in a test environment. Confirm with your AD FS team whether the auto-rollover setting is on and how the new certificate reaches Keycloak before the old one stops being used.
Encrypt assertions where policy requires it
Assertion encryption protects user attributes in transit through the browser, which matters when claims include personal data or group names that policy treats as sensitive. Decide with your security and compliance leads whether AD FS must encrypt assertions, then configure matching encryption keys on both sides. Test with a real login after each key change, because an encryption mismatch often appears only as a generic sign-in failure.
Separate the admin console hostname
Keycloak's production guidance calls for exposing the admin console and Administration REST API on a different hostname or context path from public frontend URLs. Give the admin plane its own internal name, restrict it at the reverse proxy to administrator networks, and confirm from outside that the admin paths do not answer on the public host. Brokering configuration changes flow through these endpoints, so an exposed admin path turns a federation setting into a takeover path.
Production guideKeep TLS on every hop
The SAML exchange passes through the browser, the reverse proxy, Keycloak and AD FS, and metadata is fetched over HTTPS. Verify that every AD FS endpoint in the Keycloak configuration uses HTTPS, that the certificates chain to a CA your clients trust, and that the metadata URL is not reachable over plain HTTP. Include the internal path between proxy and Keycloak in the review, since a plaintext backend hop is easy to miss.
Limit who can sign in
Keycloak trusts whatever AD FS asserts, so access limits belong in both places. Use AD FS issuance authorization and claim rules to release claims only for the groups allowed to use Keycloak, then use Keycloak first-login flows and role mappings to grant only the roles each group needs. Test with one user from an excluded group and confirm sign-in fails or receives no application role.
Testing the AD FS flow in a lab, staging and production
The lab proves that the SAML configuration works end to end before any shared system is touched. Use a non-production AD FS farm or a test relying party trust, a Keycloak instance built from the same version you plan to run, and a small set of test accounts that mirror real attributes. Keep the lab disposable so that metadata, certificates and mappers can be rebuilt from scratch when a test fails.
- Test accounts: Create one account per role you plan to map, plus one account with a missing or malformed claim, one disabled account, and one account whose UPN differs from its email address.
- SAML evidence: Capture the SAML response from the browser developer tools or a SAML tracer, and record the NameID format, the audience, the issuer, the signature status and the attribute statement for each test account.
- AD FS unreachable: Stop the AD FS endpoint or block it at the network layer, then confirm that the Keycloak login page shows the expected failure and that the local fallback or the redirector behavior matches your design.
- Logout behavior: Sign in, sign out of Keycloak, and check whether the AD FS session persists, then record the result for each logout path you support.
- Rollback: Keep a exported copy of the realm and identity provider settings so the lab can return to a known state after each change.
Check that every test account produces the same user record and role assignments on each login.
Staging repeats the lab tests on infrastructure that matches production in topology, certificates and network paths. Its purpose is to catch problems that only appear with production-like DNS names, TLS certificates, load balancers and AD FS farm configuration. Use accounts that resemble production users, and run the tests with the same Keycloak deployment method you will use in production.
- Test accounts: Use a mix of standard users, administrators, and accounts in each group that carries a Keycloak role, and confirm that group membership changes in AD FS reach Keycloak on the next login.
- SAML evidence: Compare signed assertions and signed requests against the metadata published by both parties, and keep the trace files with the change record. Review Keycloak logs for signature validation and clock skew messages.
- Metrics and login failures: Enable metrics with --metrics-enabled=true as described in the Keycloak observability guide, and watch login error counters during the test. Login failures are persisted to the database by default in Keycloak 26.8, so query those records after each failed attempt and confirm that the data meets your retention rules.
- AD FS unreachable: Simulate an outage of the AD FS farm or one of its nodes, and confirm that users see a clear message and that administrators can still reach the local admin console.
- Rollback: Confirm that the previous login path can be re-enabled by changing one setting, and time that change with the team that will perform it in production.
Record every failed test with its SAML trace and Keycloak log entry so the production team can reproduce it.
The production cutover moves real users to the AD FS login path. Plan it as a controlled change with a named owner, a window agreed with the business, and a rollback decision point agreed in advance. Keep the old login path available until the new path has passed a full working cycle with real users, and do not remove it during the first change.
- Pilot accounts: Start with a small group of named pilot users and a set of break-glass administrators who can sign in through a local path, and confirm both groups before opening the change to others.
- SAML evidence: Capture one trace per pilot user and store it with the change record, including the NameID value, the signature status and the mapped roles. Confirm that the metadata and certificates in production match the approved staging values.
- Failover case: Test the AD FS outage path in production only through an approved window, and confirm the behavior that users and help desk staff will see. Make sure your procedure states who decides whether to disable the AD FS provider during an outage.
- Logout behavior: Verify that logout from Keycloak and from applications behaves as your design states, and that sessions end on the timing you expect.
- Rollback: Define the trigger, such as a sign-in failure rate or a broken role mapping, and the exact steps to disable the provider and restore the previous path. Confirm that the rollback has been rehearsed in staging.
After the change, review the Keycloak logs and metrics for the first full business day and confirm that no unexpected errors remain.
Common AD FS to Keycloak failures and their fixes
This table lists the failures teams most often hit when brokering AD FS sign-in into Keycloak over SAML 2.0, with the likely cause and the fix for each. Use it as a first-pass checklist during testing, and confirm every fix against the Keycloak and AD FS versions you actually run, since settings and screen names change between releases.
| Symptom | Likely cause | Fix |
|---|---|---|
| Signature validation failure at login | The AD FS token-signing certificate was rotated or renewed, and Keycloak still holds the old certificate from the imported metadata or the manual upload. | Re-import the current federation metadata or upload the new signing certificate in the Keycloak SAML provider settings. Confirm in your AD FS version which certificate is primary and whether the old one stays valid for a grace period. |
| Users land on duplicate accounts or are not linked to existing users | The NameID format or value Keycloak receives differs from what the user already has, for example a UPN in one flow and an email address or sAMAccountName in another. | Pick one NameID format in the AD FS claim rules, document it, and set the matching first-login mapping in Keycloak. Clean up duplicates before enabling the provider for all users. |
| Assertion rejected as not yet valid or expired | Clock skew between the AD FS servers, the Keycloak hosts and any proxy or load balancer, so the NotBefore and NotOnOrAfter window does not match local time. | Sync all hosts to the same reliable time source and check drift on each node in the cluster. Confirm the acceptable skew allowance in your Keycloak version before changing any validity setting. |
| Invalid destination, audience or relying party identifier error | The relying party identifier in AD FS does not match the Keycloak SP entity ID, or the assertion consumer service URL in the relying party trust points to the wrong realm or hostname. | Copy the Keycloak service provider entity ID and ACS URL exactly from the realm's SAML descriptor into the AD FS relying party trust. Check for trailing slashes, http versus https and the public hostname behind any reverse proxy. |
| Required claims missing, or users have no roles or groups | A claim rule was edited or reordered in AD FS, so the attribute no longer appears in the assertion, or the Keycloak attribute mapper reads a different attribute name. | Review the issuance transform rules and capture a sample SAML response with the SAML tracer tool your team uses. Align the attribute names in the Keycloak identity provider mappers, then test with a user from each group. |
| Users reach the wrong realm or identity provider | Several realms or SAML providers share similar aliases or hostnames, the client was registered in another realm, or an identity provider redirector or kc_idp_hint routes users to the wrong provider. | Check the client redirect URIs and the realm that issued the request. Confirm the provider alias, default provider setting and any hint parameters before retesting with a clean browser session. |
| Sign-in fails after an AD FS farm failover | The federation service name changed during failover, so the issuer, metadata endpoint or signing certificate Keycloak trusts no longer matches what AD FS now sends. | Confirm the federation service name and issuer in the new farm, then update the metadata URL or issuer value in Keycloak and re-import metadata. Test both the primary and secondary farm names if DNS still points to either. |
What the AD FS integration costs and what it needs from your team
Can our team build the AD FS to Keycloak integration in-house?
Yes, a team with Keycloak administration skills and AD FS experience can build it in-house, and many do. The work touches three areas that rarely sit with one person: Keycloak realm and identity provider configuration, the AD FS relying party trust and claim rules, and the certificate and TLS material that signs and encrypts the SAML exchange. Before you start, confirm that someone on the team can change AD FS claim rules in a test environment and that the Keycloak side has an owner for the realm, clients and mappers. If either gap exists, a fixed-scope engagement with DeployOpen can cover the build while your team takes over operation. DeployOpen does not publish a price list, and a quote follows from the written scope.
What makes the AD FS integration take more effort?
The main drivers are the number of applications brokered through Keycloak, the complexity of the claims each one needs, the certificate and TLS work, the number of environments, and how well the existing AD FS setup is documented. Each additional application usually adds its own client configuration and mapper set. Claim complexity grows when you need group membership, multi-valued roles or attributes transformed before Keycloak reads them. Certificate work covers signing and encryption keys, metadata validity and the trust chain for TLS on both sides. Separate development, test and production environments multiply the testing and metadata exchanges. Ask for an inventory of the AD FS relying party trusts and claim rules before requesting a quote, because undocumented rules are the most common source of rework.
What recurring work follows the AD FS integration?
After go-live, the recurring work is certificate rotation, patching of both Keycloak and Windows Server, and upgrade testing. Signing and encryption certificates on the AD FS side expire on their own schedule, and each rotation requires updated metadata in Keycloak and a test sign-in before the old certificate is retired. Keycloak ships minor releases several times a year and the project says breaking changes in a minor release are opt-in, so each upgrade still needs a sign-in test against AD FS. Windows Server has its own lifecycle, and Keycloak and the operating system underneath it need patch windows that do not break brokered sign-in. Decide early who owns each of these tasks and how often the team will test them, and budget for that work separately from the initial build.
How much does Windows Server licensing add to the AD FS side?
The licensing cost depends on whether you already run Windows Server with AD FS and on your edition and core count. Microsoft's Windows Server 2025 pricing page lists a suggested price of 1,176 US dollars for Standard and 6,771 US dollars for Datacenter for 16 core licenses, and notes that prices vary by region. Both editions are licensed per core with a minimum of 16 cores per server and 8 per processor, and both need a Windows Server Client Access License for every user or device that accesses the server. Those CALs are a separate cost that scales with your user count. The same pricing page offers pay-as-you-go licensing through Azure Arc at 33.58 US dollars per core per month. Confirm with your Microsoft reseller or licensing advisor which edition and CAL position applies, because the integration itself does not change your Windows Server entitlement.
How long does the AD FS to Keycloak integration take?
The duration depends on the scope, so there is no single figure that applies to every organization. Timing is driven by the number of applications, the claim rules to be mapped, how many environments must be tested, and how quickly change windows can be booked on the AD FS side. Keep in mind that the AD FS administrators may need to schedule changes during approved windows, and that certificate and metadata exchanges can block progress until both sides agree. Agree the timeline in writing before work starts, and ask for it to list the milestones, the test accounts and the change windows the plan depends on. A fixed-scope agreement sets the deliverables and timeline in advance.
What must our team provide before the integration starts?
Your team needs to provide administrative access to AD FS, approved change windows on the AD FS and Keycloak environments, test accounts that represent each user type, and access to the certificate authority that issues or signs the SAML certificates. Without AD FS admin access, relying party trust and claim rule changes cannot be tested. Change windows matter because AD FS changes often need approval in production. Test accounts should cover normal users, users with group-based roles and any user who should be denied. Certificate authority access lets the team issue or confirm signing and encryption certificates and their chain. Also provide the existing AD FS documentation, a list of applications to be brokered and a named contact for the Keycloak realm and client decisions.
How DeployOpen scopes, delivers and supports the AD FS integration
DeployOpen approaches AD FS as a SAML identity provider in Keycloak as a fixed-scope engagement inside your own infrastructure. We agree the scope in writing first, then build and test the brokering path, and hand over the configuration and runbooks your team needs to operate it. Ongoing support is available as a retainer.
How we scope
- Written scope listing the AD FS farm, Keycloak realm and SAML clients in the engagement
- Agreed decisions on NameID format, signing and encryption, and claim-to-role mapping before build
- Confirmed inventory of applications that will sign in through the brokered AD FS path
How we build
- Metadata exchange and relying party trust configured with the signing and encryption certificates you approve
- Signed requests and assertions enabled and tested against your AD FS token signing settings
- Identity provider mappers built for AD FS claims, with login-time sync behavior verified for each role
How we hand over
- Documented configuration covering metadata, certificates, mappers and the sign-in flow end to end
- Test results from sign-in, logout, failed-login and certificate rotation scenarios with retest notes
- Runbook for your identity and platform teams describing what to change and what to check after updates
How we support
- Fixed-scope delivery with support and upgrade work available through a DeployOpen retainer
- Support for Keycloak upgrades and AD FS changes that affect the SAML trust or claim rules
- Retesting after configuration changes, so your team can confirm the integration still behaves as documented

