Sub topic 11
SAML single sign-on for connected apps
This chapter assumes you can create a connected app in Setup and know how profiles and permission sets grant access. It also assumes you know the difference between authentication and authorization. OAuth, covered in earlier chapters, lets an app call APIs. SAML lets a user sign in to another app without a second password.
Which direction SAML runs
SAML 2.0 involves two roles:
- The identity provider (IdP) authenticates the user and issues a signed assertion, which is an XML statement about who the user is.
- The service provider (SP) trusts the IdP and accepts the assertion in place of a login.
Two setups are easy to confuse:
| Setup | Salesforce role | Where you configure it |
|---|---|---|
| Users sign in to Salesforce with a corporate IdP | Service provider | Single Sign-On Settings |
| Users sign in to another app with their Salesforce login | Identity provider | A connected app with SAML enabled |
This chapter covers the second setup. The connected app represents the external service provider inside Salesforce.
Configuring the connected app
Before you start, enable Salesforce as an identity provider under Setup > Identity Provider. This step generates the certificate that signs assertions. Then, in the connected app, select Enable SAML and fill in the values your service provider gives you:
- Entity ID identifies the service provider. It becomes the assertion's audience.
- ACS URL is the Assertion Consumer Service URL, the endpoint that receives the assertion.
- Subject Type and Name ID Format decide which user attribute identifies the person. Usernames are often wrong for external apps, so Federation ID is the usual choice.
- Issuer is your Salesforce identity provider's identifier.
- IdP Certificate is the one used to sign. Give the matching public certificate to the service provider.
The assertion that results looks like this, trimmed to the parts that matter:
<saml:Assertion>
<saml:Issuer>https://MyDomain.my.salesforce.com</saml:Issuer>
<saml:Subject>
<saml:NameID Format="urn:oasis:names:tc:SAML:2.0:nameid-format:persistent">
fed-id-1042
</saml:NameID>
</saml:Subject>
<saml:Conditions>
<saml:AudienceRestriction>
<saml:Audience>https://app.example.com/saml/metadata</saml:Audience>
</saml:AudienceRestriction>
</saml:Conditions>
</saml:Assertion>For IdP-initiated sign-in, users open https://MyDomain.my.salesforce.com/idp/login?app=<connected app ID>. They can also click the app in the App Launcher. Salesforce checks the connected app's access rules first. Permitted Users, profiles, and permission sets apply to SAML sign-in just as they do to OAuth.
Common errors
- Audience mismatch. The Entity ID in Salesforce differs from what the service provider expects, even by a trailing slash.
- ACS URL mismatch. The service provider rejects assertions posted to a different endpoint than it registered.
- Subject not found. The Federation ID on the Salesforce user is empty or differs from the service provider's record.
- Signature failure. The service provider holds an old or expired certificate. Rotating the signing certificate breaks every service provider until each one imports the new one.
- Access denied before the assertion. The user's profile or permission set does not grant the app.
Exercise
Your service provider rejects the assertion and reports that the subject is unknown. The signature validates and the ACS URL is correct. What do you check first?
Show answer
Check that the Salesforce user's Federation ID is populated and matches the identifier the service provider stores for that person. The connected app's Subject Type must also be set to Federation ID. A wrong or empty subject value is the usual cause when the signature and endpoint are already correct.