Can I use the organization_id to match a user to a specific data set at login time?
Last Updated:
Overview
We're currently building a SaaS application for customers to use and I'm trying to guidance on how to segregate data based on organizations. Right now I have an experience where those logging in would be specifying which organization they are logging into. Since this is now part of the claims token I should be able to extract it and use it to match against data I have to show them their data specifically right?
For more context, think about it like this: we have a lot of data collected through an IoT play that we are building services off of so that the customer can see relevant data for their devices. We have several customers so the key is simply to use the authentication point to see which data to represent.
Applies To
- Organizations
- Tokens
Cause
Solution
https://community.auth0.com/t/get-users-organization-id/61490
In summary, when you make the
/authorize request in your app, you can pass the organization query string parameter to include the org_id claim in the ID Token:
loginWithRedirect({organization: 'org_abc123'})
You can later inspect the value of the organization_id from either the ID Token or the Access Token, as explained in this document:
https://auth0.com/docs/manage-users/organizations/using-tokens
You can then use the organization_id as part of your application logic.