# Getting Management API Access Tokens for SPAs

**URL:** <https://community.auth0.com/t/getting-management-api-access-tokens-for-spas/94734>\
**Category:** Get Help\
**Tags:** spa, api, oauth2\
**Created:** [November 18, 2022, 11:12pm UTC](https://community.auth0.com/t/getting-management-api-access-tokens-for-spas/94734 "2022-11-18T23:12:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![liam-ssg](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/liam-ssg/32/26496_2.png) [@liam-ssg](https://community.auth0.com/u/liam-ssg)\
**Post date:** [November 18, 2022, 11:12pm UTC](https://community.auth0.com/t/getting-management-api-access-tokens-for-spas/94734/1 "2022-11-18T23:12:22Z")

</div>

Here’s what I’m trying to do:

- Authenticate with Google to sign-in (done). I can get the user profile using auth0-spa-js, and that works.
- Get the Access Token that was issued by Google in my SPA. I think I’ll need the management API to do that.
- Call Google APIs using that access token

I have no idea how to do this without a backend. After reading several other questions that are similar, most people are redirected here: [Call an Identity Provider API](https://auth0.com/docs/authenticate/identity-providers/calling-an-external-idp-api) . The “frontend” part just says “first, build a backend.” One of the most important features of my app is that there _is_ no backend, because we don’t want to have access to all of your data! If we did, it would make the Google review process even more burdensome.

I’m referring to this document: [Get Management API Access Tokens for Single-Page Applications](https://auth0.com/docs/secure/tokens/access-tokens/get-management-api-tokens-for-single-page-applications) - it says “With a Management API Token issued for a SPA, you can access the following scopes (and hence endpoints).” and it goes on to list several scopes that make perfect sense, and are exactly what they need. Those scopes are limited to changing the currently signed-in user.

I think there’s a problem with this code, though:

```auto
          let returnToken = await auth0.getTokenWithPopup({
            authorizationParams: AUTH0_MANAGEMENT_API_CONFIG
          });

```

Where `AUTH0_MANAGEMENT_API_CONFIG` is:

```auto
{
    "audience": "https://dev-xxxxxxxxxx.us.auth0.com/api/v2/",
    "scope": "read:current_user,update:current_user_identities,create:current_user_metadata,update:current_user_metadata,delete:current_user_metadata,create:current_user_device_credentials,delete:current_user_device_credentials"
}

```

Now, the token that I get back does exist. But when I inspect it at `jwt.io`, I get: `"scope": ""`. Then, when I construct the `auth0.Management` instance:

```auto
      auth0Manage = new Management({
        domain: "dev-xxxxxxxxxxxx.us.auth0.com",
        token: managementToken
      });

```

and I try to get the identities thusly:

```auto
       // u is my user object
      auth0Manage.getUser(u.sub, (err, profile) => {
        if (err) throw err;
        console.log(profile.identities);
      });

```

Then I get `err` set to an error caused by it being unauthorized. Maybe that’s because there are no scopes, even though I’m trying to get all of them? I verified that the u.sub equals the “sub” value in the JWT that’s returned in the management token.

In the headers for the response from `/api/v2/users/<my sub>`, I see `Bearer error="Invalid token"`, if that helps.

---

<div class="post-metadata">

**Author:** ![liam-ssg](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/liam-ssg/32/26496_2.png) [@liam-ssg](https://community.auth0.com/u/liam-ssg)\
**Post date:** [November 19, 2022, 9:57pm UTC](https://community.auth0.com/t/getting-management-api-access-tokens-for-spas/94734/2 "2022-11-19T21:57:00Z")

</div>

Ah, solved it. Unlike other places where scopes are specified (for example, when defining a custom social connector), scopes must be separated with a space instead of a comma. I wish Auth0 would give some sort of error from the API when requesting invalid scopes!

---

<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:** [November 21, 2022, 9:41am UTC](https://community.auth0.com/t/getting-management-api-access-tokens-for-spas/94734/3 "2022-11-21T09:41:58Z")

</div>

Glad that it’s working now and thanks for sharing your feedback! I’ll make sure to relay it to our engineering teams!

---

<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:** [December 5, 2022, 9:42am UTC](https://community.auth0.com/t/getting-management-api-access-tokens-for-spas/94734/4 "2022-12-05T09:42:36Z")

</div>

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