SSO Login into Salesforce from Node via samlp SAML IdP
October 4, 2019 § Leave a comment
Documenting this in a blog post because it drove us crazy trying to figure out exactly what was involved, even though it was actually easy to implement once we understood all the terminology.
In order for our previously-authenticated users to automatically log into Salesforce, we needed to:
- Create a “/sso-url” on our node server for our web app to access
- When our web app GETs that URL, create and a return a SAML Identity Provider (IdP) using
samlp
- That IdP is interpreted by the web browser a redirect to the Salesforce URL (returned by the function assigned to `getPostURL`)
- Salesforce just needs to have the IdP certificate and Entity ID in its SSO Settings
Below are additional details on why we needed this.
Our Use Case
- Our customers are already logged into a node-powered React application
- Using our personal authentication
- If using e.g., Okta, there’s better out-of-the-box options
- We want them to access a protected Knowledge Base located inside Salesforce
- This requires using the SAML 2.0 SSO Flow
- Do NOT use a “Connected App”
- That is the reverse-flow where YOUR app wants to use Salesforce to do the authentication
- We did this using the
samlp
node library for creating and hosting your own Identity Provider- Beware of packages which are only intended for creating a Service Provider to work with other people’s Identity Providers
- Including one which had an “Identity Provider” constructor for *storing* the IdP credentials, but didn’t actually implement one
Shout Outs
Some incredibly helpful tools that helped us figure this out:
ngrok
which made it easy to create a public callback URL for the node server running locally on our laptop- Axiom SAML tester, the first thing we actually got running
- Chrome dev tools, including a nifty features that replays a web request as a node ‘fetch’ API call (or curl)
- https://samltest.id/ for seeing what went in each direction
Useful Documentation
- https://developer.salesforce.com/index.php?title=Single_Sign-On_for_Desktop_and_Mobile_Applications_using_SAML_and_OAuth&oldid=38890
- https://trailhead.salesforce.com/en/content/learn/modules/identity_login/identity_login_sso
- https://stackoverflow.com/questions/12779532/differences-between-sp-initiated-sso-and-idp-initiated-sso
- https://medium.com/@Ratnaparkhi/testing-saml-flow-in-your-node-js-application-1ab82f95b69d
- https://developer.salesforce.com/docs/atlas.en-us.sso.meta/sso/sso_jit_community_requirements.htm
Leave a Reply