Skip to content

How to Fix Keycloak SAML Protocol Error

DodaTech Updated 2026-06-24 2 min read

In this tutorial, you'll learn about How to Fix Keycloak SAML Protocol Error. We cover key concepts, practical examples, and best practices.

Keycloak SAML authentication returns SAML response validation failed or Invalid assertion — the SAML response from the identity provider does not match Keycloak's expected configuration.

The Problem

ERROR [org.keycloak.protocol.saml] Error processing SAML response:
SAML assertion validation failed: org.keycloak.common.VerificationException:
Signature validation failed for SAML assertion

Step-by-Step Fix

Step 1: Verify signing configuration

In the Keycloak admin console, go to Clients > SAML Client > Settings:

Client Signature Required: ON
Force POST Binding: ON
Force Name ID Format: ON
Sign Documents: ON
Sign Assertions: ON

Step 2: Import IDP metadata

# Download IDP metadata
wget https://idp.example.com/metadata -O /tmp/idp-metadata.xml

Then in Keycloak: Clients > Import > Select File.

Step 3: Configure SAML bindings

SAML Binding: POST Binding
Assertion Consumer URL: https://auth.example.com/realms/myrealm/broker/saml/endpoint

Step 4: Set up encryption

Encrypt Assertions: ON
Encryption Algorithm: AES-256

Step 5: Check audience and issuer

Expected Audience: https://auth.example.com/auth/realms/myrealm
Issuer: https://idp.example.com/metadata

Step 6: Test SAML login

curl -v "https://auth.example.com/realms/myrealm/protocol/saml?SAMLRequest=ENCODED_REQUEST"

Prevention Tips

  • Export and compare IDP metadata regularly
  • Use signed SAML assertions for security
  • Validate signature algorithms match between IDP and Keycloak
  • Test SAML flow with different browsers to rule out cache issues

Common Mistakes with saml error

  1. Non-exhaustive pattern matches that compile with warnings then crash at runtime
  2. Misunderstanding that String is [Char] with poor performance for large text operations
  3. Using foldl instead of foldl' causing stack overflow on large lists

These mistakes appear frequently in real-world KEYCLOAK code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

### Why does Keycloak reject the SAML assertion signature?

The signature algorithm on the IDP must match what Keycloak expects. Keycloak defaults to RSA-SHA256. Check the IDP configuration for signature algorithm and ensure certificates are correctly exchanged. The IDP's signing certificate must be in Keycloak's truststore.

What is the difference between signing the SAML document and signing the assertion?

Signing the document signs the entire SAML response. Signing the assertion signs only the <saml:Assertion> element. Signing the assertion allows the SP to cache and reuse the assertion independently. For most setups, enabling both is recommended.

How do I debug SAML errors in Keycloak?

Enable SAML debug logging: sudo /opt/keycloak/bin/kc.sh start --log-level=org.keycloak.protocol.saml:debug. Check /opt/keycloak/data/log/server.log for detailed SAML message processing traces.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro