# SAML Decoder and Validator API

> Decode SAMLResponse / SAMLRequest (POST or Redirect) and IdP metadata to JSON, verify XML signatures, flag audience, expiry and signature wrapping issues.

- Endpoint: `GET | POST https://apibox.io.vn/v1/saml-tools`
- Category: Security & Crypto
- HTML docs: https://apibox.io.vn/docs/saml-tools/ (Vietnamese: https://apibox.io.vn/vi/docs/saml-tools/)
- Online tool: https://apibox.io.vn/tools/saml-tools/
- Authentication: `Authorization: Bearer <API key>` or `X-API-Key: <API key>` (free key: https://apibox.io.vn/dashboard/#signup)

Paste a `saml` value — the base64 `SAMLResponse` / `SAMLRequest` of the POST binding, the base64 + DEFLATE value of the Redirect binding, or raw XML — or a full Redirect `url` with its query string. Responses come back as JSON: status, issuer, destination, InResponseTo, the assertion with NameID and format, SubjectConfirmationData (recipient, NotOnOrAfter), Conditions (NotBefore, NotOnOrAfter, audiences), AuthnStatement (session index, AuthnContextClassRef) and attributes as `name -> [values]`. AuthnRequest, LogoutRequest / LogoutResponse and metadata (`EntityDescriptor` / `EntitiesDescriptor`: SSO, SLO and ACS endpoints, NameID formats, signing / encryption certificates with fingerprints and expiry) are read too.

Every XML signature is verified: references by ID with the enveloped-signature transform, exclusive C14N (with InclusiveNamespaces) and inclusive C14N 1.0, SHA-1/256/384/512 digests, RSA and ECDSA signatures with WebCrypto. Give the IdP certificate as `cert` (PEM) or its `fingerprint` (SHA-256 / SHA-1) — a signature that only matches its own embedded certificate is reported as not trusted. Redirect-binding query signatures (`SigAlg`, `Signature`) are verified against `cert` as well.

Configuration checks become `errors` and `warnings`: unsigned messages, signatures over another element than the one that is read, nested or duplicated assertions and duplicate IDs (signature wrapping), comments inside NameID, SHA-1, expired or not-yet-valid conditions (`clock_skew_s`, default 180 s; `now` to test old samples), missing audience restriction and mismatches with `expected_audience`, `expected_recipient` (ACS URL), `expected_issuer` and `expected_request_id`. XML with a DOCTYPE is refused (XXE). `op=sp-metadata` generates SP metadata from `entity_id`, `acs_url`, `slo_url` and `cert`. Encrypted assertions are not decrypted; nothing is stored.

## Parameters

| Name | In | Type | Required | Default | Description |
|---|---|---|---|---|---|
| `saml` | body|query | string | yes |  | Base64 SAMLResponse / SAMLRequest (POST), base64 + DEFLATE (Redirect), or XML (response, request, assertion, metadata). Max 1 MB of XML. |
| `url` | body|query | string | no |  | A Redirect-binding URL with SAMLRequest / SAMLResponse, RelayState, SigAlg and Signature. |
| `cert` | body | string | no |  | Trusted IdP certificate(s), PEM or base64 (up to 5). |
| `fingerprint` | body|query | string | no |  | SHA-256 or SHA-1 fingerprint of the trusted certificate (hex, colons allowed). |
| `expected_audience` | body|query | string | no |  | Your SP entity ID. |
| `expected_recipient` | body|query | string | no |  | Your ACS URL (checked against Recipient and Destination). |
| `expected_issuer` | body|query | string | no |  | IdP entity ID. |
| `expected_request_id` | body|query | string | no |  | ID of your AuthnRequest (InResponseTo). |
| `clock_skew_s` | body|query | number | no | `180` | Allowed clock skew in seconds (0-3600). |
| `now` | body|query | string | no |  | Check time validity at this ISO time instead of now (testing old samples). |
| `op` | body|query | string | no | `decode` | `decode` or `sp-metadata` (with entity_id, acs_url, slo_url, cert, name_id_format, want_assertions_signed, authn_requests_signed; format=xml for the file). |
| `include_xml` | body|query | boolean | no | `false` | Also return the decoded XML. |

## Example request

```bash
curl -X POST "https://apibox.io.vn/v1/saml-tools" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"saml":"PHNhbWxwOlJlc3BvbnNlIHhtbG5zOnNhbWxwPSJ1cm46b2FzaXM6bmFtZXM6dGM6U0FNTDoyLjA6cHJvdG9jb2wi…","cert":"-----BEGIN CERTIFICATE-----\nMIIDP…\n-----END CERTIFICATE-----","expected_audience":"https://sp.example.vn/metadata","expected_recipient":"https://sp.example.vn/acs","expected_request_id":"_req42"}'
```

## Example response

```json
{
  "type": "Response",
  "encoding": "base64 (POST binding)",
  "id": "_resp1",
  "issue_instant": "2026-11-11T10:00:00Z",
  "destination": "https://sp.example.vn/acs",
  "in_response_to": "_req42",
  "issuer": "https://idp.example.com/",
  "status": {
    "code": "Success",
    "sub_code": null,
    "message": null,
    "success": true
  },
  "assertion": {
    "id": "_assert1",
    "issue_instant": "2026-11-11T10:00:00Z",
    "version": "2.0",
    "issuer": "https://idp.example.com/",
    "subject": {
      "name_id": {
        "value": "an@example.vn",
        "format": "urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress",
        "name_qualifier": null,
        "sp_name_qualifier": null
      },
      "confirmation_method": "bearer",
      "recipient": "https://sp.example.vn/acs",
      "not_on_or_after": "2026-11-11T10:05:00Z",
      "in_response_to": "_req42"
    },
    "conditions": {
      "not_before": "2026-11-11T09:59:30Z",
      "not_on_or_after": "2026-11-11T10:05:00Z",
      "audiences": [
        "https://sp.example.vn/metadata"
      ],
      "one_time_use": false
    },
    "authn": {
      "authn_instant": "2026-11-11T09:59:58Z",
      "session_index": "_sess9",
      "session_not_on_or_after": null,
      "context_class": "urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport"
    },
    "attributes": {
      "email": [
        "an@example.vn"
      ],
      "groups": [
        "dev",
        "admin & ops"
      ]
    }
  },
  "signed": {
    "response": false,
    "assertion": true
  },
  "age_seconds": 60,
  "signatures": [
    {
      "path": "/Response/Assertion/Signature",
      "signed_element": "/Response/Assertion",
      "signed_id": "_assert1",
      "references": [
        {
          "uri": "#_assert1",
          "digest_ok": true,
          "digest_algorithm": "sha256",
          "transforms": [
            "enveloped-signature",
            "exc-c14n"
          ]
        }
      ],
      "canonicalization": "exc-c14n",
      "signature_algorithm": "rsa-sha256",
      "signature_valid": true,
      "valid": true,
      "key_source": "cert parameter",
      "trusted": true
    }
  ],
  "valid": true,
  "errors": [],
  "warnings": []
}
```

## Use cases

- Debug "SSO does not work" tickets from Entra ID, Okta, Google Workspace or Keycloak customers
- Check that your SP validates audience, recipient and expiry before going live
- Read IdP metadata and get its signing certificate and endpoints as JSON
- Generate SP metadata to send to a customer’s identity team

## FAQ

### Is it safe to paste a production SAML response?

It is processed in memory and never stored or logged, but it contains personal data and is valid for minutes: prefer expired or test responses.

### Why is my valid signature "not trusted"?

Without "cert" or "fingerprint" the only key is the certificate embedded in the message, which an attacker could replace. Pass the certificate from your IdP metadata.

### Can it decrypt EncryptedAssertion?

No: that needs your SP private key, which should never leave your server. The outer response is still checked.
