# How can my backend know which company a user belongs to?

**URL:** <https://community.auth0.com/t/how-can-my-backend-know-which-company-a-user-belongs-to/35775>\
**Category:** Get Help\
**Tags:** claims, jwt, api, scopes, permissions\
**Created:** [January 3, 2020, 10:03am UTC](https://community.auth0.com/t/how-can-my-backend-know-which-company-a-user-belongs-to/35775 "2020-01-03T10:03:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jk.chauhan](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jk.chauhan/32/18271_2.png) [@jk.chauhan](https://community.auth0.com/u/jk.chauhan)\
**Post date:** [January 3, 2020, 10:03am UTC](https://community.auth0.com/t/how-can-my-backend-know-which-company-a-user-belongs-to/35775/1 "2020-01-03T10:03:09Z")

</div>

Hi All,

I am building an SPA with a backend API that will be used by multiple companies, with each company having several users.

The problem I am facing is that if I have 2 users, one from company X and one from company Y, how can my backend know which company that user belongs to so that it can return the correct data to the user?

Do I add permissions to the users e.g. company:companyX & company:companyY so that my backend can distinguish between the users?

Or is there another (better) method for doing this?

Thanks!

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [January 3, 2020, 8:18pm UTC](https://community.auth0.com/t/how-can-my-backend-know-which-company-a-user-belongs-to/35775/3 "2020-01-03T20:18:46Z")

</div>

Hi @jk.chauhan,

Welcome to the Auth0 Community Forum!

I think using metadata could be a reasonable solution for this.

> **[Understand How Metadata Works in User Profiles](https://auth0.com/docs/manage-users/user-accounts/metadata)**
>
> Describes Auth0 user, application, and client metadata. Learn how you can use metadata to store information that does not originate from an identity provider.

You can add the users metadata to the access token as a custom claim.

> **[Sample Use Cases: Scopes and Claims](https://auth0.com/docs/get-started/apis/scopes/sample-use-cases-scopes-and-claims)**
>
> Learn how to use scopes and claims with applications and APIs.

Hope this helps!

Thanks,  
Dan

---

<div class="post-metadata">

**Author:** ![jk.chauhan](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jk.chauhan/32/18271_2.png) [@jk.chauhan](https://community.auth0.com/u/jk.chauhan)\
**Post date:** [January 5, 2020, 12:42pm UTC](https://community.auth0.com/t/how-can-my-backend-know-which-company-a-user-belongs-to/35775/5 "2020-01-05T12:42:55Z")

</div>

Hi Dan

Thanks for your message.

I have successfully managed to write the rule I am able to get the company that the user belongs to in the id token after setting it in the app\_metadata.

My next question is how can my backend get this information as well?  
The app\_metadata is only set in the id token which doesn’t get sent to the api so it still has no knowledge of which company the user belongs to.

I’ve read about the /userinfo api endpoint for getting user information so should my backend make a call to the endpoint and get the app\_metadata that way? And should it use the access token that the client sent to it to access this api?

Thanks

Jay

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [January 19, 2020, 4:42pm UTC](https://community.auth0.com/t/how-can-my-backend-know-which-company-a-user-belongs-to/35775/6 "2020-01-19T16:42:58Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
