Watching the Wire
Deze inhoud is nog niet vertaald.
Module 3 of 6 in the chapter Watching the Door: Troubleshooting and Audit, chapter 16 of Securing Salesforce: Identity and Access. Each module stands on its own.
The question this module answers: When the logs don’t say enough, how do you watch the login as it happens?
It’s not magic
Section titled “It’s not magic”When I demo single sign-on, I turn on SAML Tracer before I log in, so we can watch the back and forth. The browser goes to Salesforce, Salesforce sends it to the identity provider, the identity provider sends it back with a signed message. On the screen it looks like one click. On the wire it’s a conversation, and you can read every line of it. It’s not magic. It’s technology, and every message has to be exactly right.
Module 2’s logs tell you what a system decided. Sometimes that isn’t enough. Login History says Audience Invalid, but which audience did the identity provider send? The app says the login failed, but what did Salesforce actually answer? For that, you watch the messages themselves. Every door in this course has a place on the wire where its error shows, and this module goes door by door.
SAML: catch the assertion
Section titled “SAML: catch the assertion”Chapter 6, module 4 taught you to read a SAML request and response. Here you use that on a failure. Salesforce’s own single sign-on article says the same: “Use a SAML tracing tool such as the SAML Tracer browser extension to capture the assertion” (K2).
Turn the tracer on, then reproduce the failure as the user, not as an admin (chapter 4’s rule: test with a user). Find the response coming back to Salesforce, open the assertion, and compare it, value by value, with the single sign-on setting:
- the Issuer against the identity provider’s Entity ID in the setting;
- the Audience against Salesforce’s Entity ID;
- the Recipient against the login URL;
- the Subject against the user’s Federation ID, character by character (module 1: case and spaces count);
- the times against a clock you trust (chapter 6: the clocks).
Or paste the assertion into the SAML Assertion Validator (chapter 6, module 7), which does the comparing for you. The tracer shows you what was sent; the validator tells you what’s wrong with it. And if no response comes back to Salesforce at all, the failure is at the identity provider, and module 2 sent you to its logs.
One caution. An assertion is a signed statement about a real person, and in a tracer it’s sitting in plain text. Capture it in a test, share it with care, and don’t paste one from production into a tool you don’t control.
OAuth: read the error the app got
Section titled “OAuth: read the error the app got”OAuth fails differently. There’s no assertion to catch; there’s an error, and Salesforce sends it back to the app. In Salesforce’s words: “The authorizing server sends an error to the callback URL with an error code” (S6). For the web server flow, it arrives in the URL as error= and a description. From the token endpoint, it comes back in the JSON answer (S6).
So the first move is to look at what the app got. In a browser, the developer tools’ network view shows the redirect and its URL. In Postman or a log from the integration, it’s the token endpoint’s answer. Then look the code up in Salesforce’s list (S6). The ones you’ll see most:
redirect_uri_mismatch: “Redirect URI mismatch with connected app definition” (S6). The callback URL the app sent isn’t exactly one on the app. Exactly: a trailing slash,httpagainsthttps, a different port.invalid_app_access: “User isn’t approved by an admin to access this app” (S6). The app is set to admin-approved users, and this user isn’t in a profile or permission set for it (chapter 13).invalid_client_idandinvalid_client: the consumer key or the secret is wrong (S6).invalid_grant: the one with many causes. An expired or used authorization code, an expired or revoked refresh token, a wrongcode_verifierfor PKCE, a user outside the IP ranges or login hours, an assertion that’s wrong, or client credentials sent to login.salesforce.com instead of your My Domain (S6). The description after the code tells you which, so read it.
Salesforce’s list also has codes for the code you wrote: REGISTRATION_HANDLER_ERROR, “a problem with your registration handler Apex code” for an auth provider (S6, chapter 10), and ERROR_CREATING_USER (S6).
The new app that doesn’t work yet. In class I made a connected app and had a token within ten minutes, and I said so, because it doesn’t always work for me first time. A new app, or a change to one, can take a while before every Salesforce server knows about it. Salesforce’s own setup guide for its MCP servers says a new external client app “can take up to 30 minutes to become available” (S14). So if a brand-new app fails and nothing looks wrong, wait a few minutes and try again before you start changing settings. Changing three things at once is how you lose track of which screw it was.
Just-in-time provisioning: the error is in the URL
Section titled “Just-in-time provisioning: the error is in the URL”When just-in-time provisioning fails (chapters 6 and 14), the user doesn’t arrive, and Salesforce puts the reason in the URL: ErrorCode, ErrorDescription and ErrorDetails (S7). If you’ve set a custom error URL in the single sign-on setting, she’s sent there with the same parameters (S7). Watching the wire, you’ll see them on the redirect.
The codes are numbered, and the list is in Salesforce Help (S7). A few: 1, missing Federation ID; 2, mismatched Federation ID; 11, license limit exceeded; 16 and 17, a profile or role name that isn’t found; 27 and 28, more than one matching contact or account (chapter 14’s matching order); 39, an invalid JIT handler class; 41, an execution error in it (S7). Number 11 is worth a moment. Just-in-time can work perfectly for months and then stop for new people only, on the day the licenses run out.
Your own code: the debug log
Section titled “Your own code: the debug log”Four doors in this course run code you wrote: the JIT handler (chapter 6), the registration handler (chapter 10), the Login Discovery handler (chapter 15) and a login flow (the Front Door chapter). When the error says the handler failed, the wire has told you all it can. Now you need the handler’s own log.
Salesforce writes Apex debug logs only when a trace flag asks for them: for a user, an Apex class or a trigger, with a start and end time and a debug level, set in Setup under Debug Logs or in the Developer Console (S12). Set the flag first, then reproduce the failure. You need View All Data to read the logs (S12).
The question is which user to trace. A handler often runs as a user named in its setting, not as the person logging in, who may not exist yet: Execute Registration As for a registration handler (chapters 10 and 14), Execute Login As for a Login Discovery handler (chapter 15), and Execute Handler As for a custom JIT handler (chapter 12; S7’s code 40 is an invalid execution user). So put the trace flag on that user, or on the handler class (S12). This course hasn’t yet tested which of the two catches a JIT handler’s log, so set both.
Test knowledge. In my experience, know where each kind of login shows its error: the SAML assertion (a tracer or the validator), the OAuth error code on the callback URL or from the token endpoint, the JIT error in the URL, and a debug log for your own handler. Be ready to name the likely cause from the error.
What’s next
Section titled “What’s next”Module 4: the usual failures, every mechanism. A symptom table, from chapter 6’s five to the OAuth and handler failures in this module.
What an architect decides here
Section titled “What an architect decides here”- The tools on the team’s machines before the bad day: a SAML tracer, the browser’s developer tools, a way to call the token endpoint.
- A custom error URL for JIT, so a failed provisioning sends people somewhere useful.
- Who may capture assertions and tokens, and where they may be kept.
- Error handling in every handler you write, with a clear message, because its failure is a login failure.
Explore
Section titled “Explore”- OAuth 2.0 Authorization Errors (opens in a new tab) (Salesforce Help; checked 2026-11-21)
- Just-in-Time Provisioning Errors (opens in a new tab) (Salesforce Help; checked 2026-11-21)
- Create an External Client App (Hosted MCP Servers) (opens in a new tab) (Salesforce Developers; checked 2026-11-21)
- Set Up Debug Logging (opens in a new tab) (Salesforce Help; checked 2026-11-21)
