If your SaaS product’s backend is built with Node.js and you want to add SSO functionality for your customers, you can do a dry-run of the SSO integration using our example Node.js app. It makes use of the WorkOS Node.js SDK to authenticate users via SSO.
1. In your CLI, navigate to the directory into which you want to clone this git repo:
2. Clone the Node.js example app’s GitHub repo:
3. Navigate to the cloned repo:
4. Install the dependencies:
6. Create a .env file in the example app’s project directory, node-sso-example/. (This file is listed in this repo's .gitignore file, so your sensitive information will not be checked into version control.).
7. Open the .env file with your preferred text editor and add the WORKOS_API_KEY and WORKOS_CLIENT_ID;
8. To ensure the example app is served as expected, start the server:
9. Navigate to http://localhost:3000. You should see this home page:
10. If you click the “Login” button you will see an error page if you haven’t properly configured SSO in the WorkOS dashboard yet.
11. Stop the Node.js server for now by typing CTRL + c in the CLI.
12. Follow the SSO authentication flow instructions to create a new SSO connection in your WorkOS dashboard.
13. Add http://localhost:3000/callback as a Redirect URI in the Configuration section of the Dashboard:
14. Update the routes/index.js file so that the const domain variable is set to your company’s Connection domain or Connection ID. It is set to “gmail.com” by default.
Then, click the arrow in the row that corresponds to the SSO Connection. This will take you to the Connection detail page where you’ll find the Connection ID:
15. Start the server again by running this command in the CLI:
16. Navigate to http://localhost:3000/ and click the Login button. You should be prompted to sign in using the IdP you configured during the SSO setup.
Nice work! You just set up SSO!