Use the organization_id to match a user to a specific data set at login time

Problem statement

We are building a SaaS application and want to segregate data based on organizations associated with user log-in. Can I use the organization_id to match a user to a specific data set at login time?

Solution

The below community topic explains how to achieve this:

  • pass the organization query string parameter to include the org_id claim in the ID Token when making the /authorize request in your app:
    loginWithRedirect({organization: 'org_abc123'})

  • inspect the value of the organization_id from either the ID Token or the Access Token, as explained in this document:

  • use the organization_id as part of your application logic.