Quick StartAdd Single Sign-On (SSO) for all Identity Providers to your app.Install the WorkOS SDKWorkOS offers native SDKs in several popular programming languages. Choose a language below to see instructions in your application’s language.npm install @workos-inc/node
You can also download the workos-node source code from GitHub.Set environment variablesAs a best practice, your WorkOS API key should be kept secret and set as an environment variable on process start. The SDK is able to read the key automatically if you store it in an environment variable named WORKOS_API_KEY, otherwise, you will need to set it manually. The Client ID should also be set dynamically based on the release environment.WORKOS_API_KEY='sk_example_123456789'
WORKOS_CLIENT_ID='client_123456789'
Add an endpoint to initiate SSOThe endpoint to initiate SSO via the WorkOS API is responsible for simply handing off the rest of the authentication workflow to WorkOS. There are a couple configuration options shown below.You can use the optional state parameter to encode arbitrary information to help restore application state between redirects.npm install @workos-inc/node
Add a callback endpointNext, add the redirect endpoint which will handle the callback from WorkOS after a user has authenticated with their Identity Provider. This endpoint should exchange the authorization code (which is valid for 10 minutes) returned by WorkOS with the authenticated user's Profile.npm install @workos-inc/node
Configure a redirect URIYou'll need to set a redirect URI (i.e. the callback endpoint from Add a callback endpoint) via the WorkOS Dashboard. Be sure not to include wildcard subdomains or query parameters.
Multi-tenant apps will typically have a single redirect URI specified. You can set multiple redirect URIs for single tenant apps, but be sure to specify which redirect_uri to use in the WorkOS client call to fetch the authorization URL.In the IdP-initiated authentication flow, the default redirect URI is used.