# How to get access tokens from auth0 management API?

**URL:** <https://community.auth0.com/t/how-to-get-access-tokens-from-auth0-management-api/59358>\
**Category:** Get Help\
**Tags:** api\
**Created:** [March 13, 2021, 12:40am UTC](https://community.auth0.com/t/how-to-get-access-tokens-from-auth0-management-api/59358 "2021-03-13T00:40:31Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![victor-wei126](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/victor-wei126/32/28140_2.png) [@victor-wei126](https://community.auth0.com/u/victor-wei126)\
**Post date:** [March 13, 2021, 12:40am UTC](https://community.auth0.com/t/how-to-get-access-tokens-from-auth0-management-api/59358/1 "2021-03-13T00:40:31Z")

</div>

I am following this code in the docs to get an access token from the management API: [Get Management API Access Tokens for Production](https://auth0.com/docs/tokens/management-api-access-tokens/get-management-api-access-tokens-for-production)

However, I read that this shouldn’t be done on the frontend because of the client secret. So what I have done is that when a user clicks a button, axios sends a get request to my backend server. Then, the server initiates the POST request as detailed in the docs above.

I’m not sure if this is the right way to do this, but I don’t think it is. It is currently giving me a 401 unauthorized error. However, when I test this request on postman, it works fine. So I’m guessing I’m doing the request in the wrong “environment”.

Is axios supposed to be used on the backend? And it seems sort of repetitive that I have to do two requests to get one response.

---

<div class="post-metadata">

**Author:** ![Ale](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ale/32/50860_2.png) [@Ale](https://community.auth0.com/u/Ale)\
**Post date:** [March 13, 2021, 2:50am UTC](https://community.auth0.com/t/how-to-get-access-tokens-from-auth0-management-api/59358/3 "2021-03-13T02:50:31Z")

</div>

Welcome to the Auth0 Community, Victor!

I assume you are implementing a SPA. The best solution for you will depend on what you want to achieve because Management API Tokens for SPAs have certain limitations. Specifically, they are issued in the context of the user who is currently signed in to Auth0 which limits updates to only the logged-in user’s data. Although this restricts the use of the Management API, it can still be used to perform actions related to updating the logged-in user’s user profile.

Important: Auth0 does not recommend putting Management API Tokens on the frontend that allow users to change user metadata.

You have many more details about all of the above on [Get Management API Access Tokens for Single-Page Applications](https://auth0.com/docs/tokens/management-api-access-tokens/get-management-api-tokens-for-single-page-applications)

Now, if you want to issue non-restricted Access Tokens because your use case requires it, the only secure solution would be to request them from a backend, so from what I understood you are in the right path. This means following [Get Management API Access Tokens for Production](https://auth0.com/docs/tokens/management-api-access-tokens/get-management-api-access-tokens-for-production) from your backend.

I hope this clarifies a bit.

---

<div class="post-metadata">

**Author:** ![victor-wei126](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/victor-wei126/32/28140_2.png) [@victor-wei126](https://community.auth0.com/u/victor-wei126)\
**Post date:** [March 13, 2021, 3:04am UTC](https://community.auth0.com/t/how-to-get-access-tokens-from-auth0-management-api/59358/4 "2021-03-13T03:04:35Z")

</div>

Hi Ale, thank you for your help. Now that you bring it up, what use cases should I use a non-restricted Access Tokens for the management API?

For most of my use cases, I would like to update user\_metadata and app\_metadata, and give certain permissions to people based on their roles. However, only I would be setting up these permissions, roles, etc. during development. The main things the user themselves can do is just editing their profile, creating new posts. Do you think I only need the tokens for SPAs then?

---

<div class="post-metadata">

**Author:** ![Ale](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ale/32/50860_2.png) [@Ale](https://community.auth0.com/u/Ale)\
**Post date:** [March 14, 2021, 1:59am UTC](https://community.auth0.com/t/how-to-get-access-tokens-from-auth0-management-api/59358/5 "2021-03-14T01:59:51Z")

</div>

With a non-restricted Access Token issued for the Management API, you could do many more things that would not be related to the logged-in current user. Think about it as being able to act just as the logged-in user (SPA Access Token) vs being able to act as the admin of your tenant.

Some examples of things you could do with a non-restricted Access Token would be to edit other users’ profiles or just edit any other data that are not related to users such as [clients](https://auth0.com/docs/api/management/v2#!/Clients/patch_clients_by_id), [connections](https://auth0.com/docs/api/management/v2#!/Connections/patch_connections_by_id), or maybe search [logs](https://auth0.com/docs/api/management/v2#!/Logs/get_logs)… the possibilities are almost endless in the sense that you would have tenant-admin powers if you wanted to.

> [@victor-wei126](#):
>
> Do you think I only need the tokens for SPAs then?

For the most part, yes. Everything that involves editing the currently logged-in users, yes, it should be doable. However, you’ve mentioned permissions, roles, etc. This is something that can be implemented in many different ways, including Auth0 ways such as [Authorization Core vs. Authorization Extension](https://auth0.com/docs/authorization/authorization-core-vs-authorization-extension) and it could also be implemented externally, for example by leveraging user metadata to store those permissions and roles. In a nutshell, if the logged-in users only need to view and/or edit their current profile, then yes, Access Tokens issued for SPA would do the job.

---

<div class="post-metadata">

**Author:** ![victor-wei126](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/victor-wei126/32/28140_2.png) [@victor-wei126](https://community.auth0.com/u/victor-wei126)\
**Post date:** [March 14, 2021, 7:25pm UTC](https://community.auth0.com/t/how-to-get-access-tokens-from-auth0-management-api/59358/6 "2021-03-14T19:25:05Z")

</div>

Hi Ale,

Thanks again for the help. With a non-restricted access token, I would be able to act as the admin of my application essentially, from what I understand. Then what is the advantage of using the management API vs just using the auth0 dashboard to edit these things? Is it that it gives me a way as an “employee” to manage users directly from my application, instead of using the dashboard? Or are there are use cases?

In this cases, I will use the SPA tokens then. To edit permissions and roles, then how do I use the authorization core? Have I not been using it already with the auth0 dashboard and such, or is that something completely different?

---

<div class="post-metadata">

**Author:** ![Ale](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ale/32/50860_2.png) [@Ale](https://community.auth0.com/u/Ale)\
**Post date:** [March 16, 2021, 3:04am UTC](https://community.auth0.com/t/how-to-get-access-tokens-from-auth0-management-api/59358/7 "2021-03-16T03:04:47Z")

</div>

> [@victor-wei126](#):
>
> With a non-restricted access token, I would be able to act as the admin of my application essentially, from what I understand. Then what is the advantage of using the management API vs just using the auth0 dashboard to edit these things? Is it that it gives me a way as an “employee” to manage users directly from my application, instead of using the dashboard?

The Dashboard is a visual UI that is easier and sometimes quicker to use than the Management API. You can use the Management API from inside your application or from any other place such as a UNIX shell, a HTTP client or any other script or app. It gives you huge flexibility on how you want to manage your tenant and the data it contains.There are too many potential use cases for me to describe them all, from developing your own custom Auth0 Dashboard to provide users with administrative access or certain permissions (defined by the scopes that you can assign to the Access Tokens they could use).

> [@victor-wei126](#):
>
> In this cases, I will use the SPA tokens then. To edit permissions and roles, then how do I use the authorization core? Have I not been using it already with the auth0 dashboard and such, or is that something completely different?

As I mentioned in my previous response, there are several ways to implement roles and permissions. Currently, Authorization Core is not something that can be managed with a restricted SPA Access Token. If you take a look at [Assign Roles to Users via Management API](https://auth0.com/docs/users/assign-roles-to-users#management-api), you will notice that the Management API Access Token requires the scopes `read:roles` and `update:users`. We don’t have those scopesin a restricted SPA Management API Access Token as documented on [Get Management API Access Tokens for Single-Page Applications](https://auth0.com/docs/tokens/management-api-access-tokens/get-management-api-tokens-for-single-page-applications#available-scopes-and-endpoints).

If you really want to use Authorization Core and handle it via Management API, then you would need to call our Management API from your backend so you can have any scope you need without the restrictions that a SPA application imposes.

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [March 16, 2021, 11:57am UTC](https://community.auth0.com/t/how-to-get-access-tokens-from-auth0-management-api/59358/8 "2021-03-16T11:57:37Z")

</div>

Thanks for helping on this one @Ale !

---

<div class="post-metadata">

**Author:** ![victor-wei126](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/victor-wei126/32/28140_2.png) [@victor-wei126](https://community.auth0.com/u/victor-wei126)\
**Post date:** [March 17, 2021, 7:23pm UTC](https://community.auth0.com/t/how-to-get-access-tokens-from-auth0-management-api/59358/9 "2021-03-17T19:23:21Z")

</div>

Thanks for the help. It seems that the easiest to assign permissions and roles is through the dashboard then? I don’t think I need to do any of the use cases you outlined above with the Management API. The extra scopes not offered by the SPA tokens, such as update:users, or read:roles, I can probably do through the dashboard?

Also, I have visited the page “get management API tokens for SPA” many times, but it only offers ways to do so manually and for testing. How do I get tokens automatically? Do I use the react SDK and getAccessTokensSilently() function? Thanks!

---

<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:** [April 1, 2021, 7:23pm UTC](https://community.auth0.com/t/how-to-get-access-tokens-from-auth0-management-api/59358/10 "2021-04-01T19:23:26Z")

</div>

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