# Service account / tenant token

**URL:** <https://community.auth0.com/t/service-account-tenant-token/57328>\
**Category:** Get Help\
**Tags:** cli, api, help, management-api, auth0\
**Created:** [February 4, 2021, 8:35am UTC](https://community.auth0.com/t/service-account-tenant-token/57328 "2021-02-04T08:35:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![arnaudp](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/arnaudp/32/12742_2.png) [@arnaudp](https://community.auth0.com/u/arnaudp)\
**Post date:** [February 4, 2021, 8:35am UTC](https://community.auth0.com/t/service-account-tenant-token/57328/1 "2021-02-04T08:35:31Z")

</div>

Hello 👋

I’m building a multi-tenant SaaS application storing tenant details in the users `app_metadata` field [as suggested here](https://auth0.com/docs/best-practices/multi-tenant-apps-best-practices#store-tenant-details-in-app_metadata). I want to distribute a CLI that customers can use on _shared hosts_ (such as their CI infrastructures) with access to the API.

- I understand how the Device Authorization Flow can help me protect this CLI with end-user authentication. But that would mean having an end-user’s token on a shared host. _(This is what I have implemented so far as I’m failing to figure out a better solution)._
- I understand how the Client Authorization Flow can help me protect this CLI with client-based authentication. But that would mean that the access token wouldn’t hold any tenant information (unless I’m missing a way to somehow customize the issued token?).
- I believe what I really need is a “tenant access token”, bound to no particular user, yet holding the tenant information (which the API uses to restrict access).

One thing I considered is to create a “service account” user per tenant, but I don’t see any way (for example through the Management API) to generate an access token for a user outside of the authorization flow. I guess I could initiate a Resource Owner Password Flow from my backend and generate an access token for that service account but it feels… wrong.

Am I missing something obvious? Is none of this making sense? I’m pretty new to all this so feel free to challenge my entire reasoning here, it won’t hurt my feelings 🙂

Thanks!

---

<div class="post-metadata">

**Author:** ![stephanie.chamblee](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/stephanie.chamblee/32/26087_2.png) [@stephanie.chamblee](https://community.auth0.com/u/stephanie.chamblee)\
**Post date:** [February 8, 2021, 5:16pm UTC](https://community.auth0.com/t/service-account-tenant-token/57328/3 "2021-02-08T17:16:47Z")

</div>

Hi @arnaudp,

Based on the Authorization Flow guide ([Which OAuth 2.0 Flow Should I Use?](https://auth0.com/docs/authorization/which-oauth-2-0-flow-should-i-use)) it sounds like Client Credentials flow is right for your situation since the client is the resource owner.

With Client Credentials flow, you can add tenant-specific data to tokens in custom claims by using a `Client Credentials Exchange` hook:

> **[Customize Tokens Using Hooks with Client Credentials Flow](https://auth0.com/docs/get-started/authentication-and-authorization-flow/customize-tokens-using-hooks-with-client-credentials-flow)**
>
> Learn how to use Hooks to change scopes and add custom claims in the access token obtained using the Client Credentials Flow.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [February 23, 2021, 5:17pm UTC](https://community.auth0.com/t/service-account-tenant-token/57328/4 "2021-02-23T17:17:20Z")

</div>

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