# Confusion on /userinfo vs. /api/v2/users/{id} apis

**URL:** <https://community.auth0.com/t/confusion-on-userinfo-vs-api-v2-users-id-apis/115195>\
**Category:** Get Help\
**Tags:** users, management-api\
**Created:** [September 1, 2023, 8:29am UTC](https://community.auth0.com/t/confusion-on-userinfo-vs-api-v2-users-id-apis/115195 "2023-09-01T08:29:17Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![dean2](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dean2/32/35668_2.png) [@dean2](https://community.auth0.com/u/dean2)\
**Post date:** [September 1, 2023, 8:29am UTC](https://community.auth0.com/t/confusion-on-userinfo-vs-api-v2-users-id-apis/115195/1 "2023-09-01T08:29:17Z")

</div>

None of the java flows work as I was adding to an opensource project webpieces Auth0Plugin.java (ie. this is all ‘backend server code’) which is working now except for I would like to get the google token to talk to the gmail api or any google api.

The current flow is redirecting to this which sends back to a /callback url →

```
	String url = "https://"+domain+"/authorize" +
			"?response_type=code" +
			"&client_id=" + auth0Config.getClientId() +
			"&scope=" + urlEncodedScope +
			"&state="+urlEncodedSecret+
			"&redirect_uri="+ urlEncodedCallbackUrl.get();

```

My current scopes are “openid profile email phone”

This is working and I currently call /userinfo for token validation. It seems like /api/v2/users/{id} might validate the token for us as well (and we need the user info anyways).

**The only issue being is I have no {id} parameter**. How do I get /api/v2/users/{id} of the current user but I do not have the {id} to do that such that I can [follow this document](https://auth0.com/docs/authenticate/identity-providers/calling-an-external-idp-api?_gl=1*ndgrsw*_gcl_aw*R0NMLjE2OTMxNDQyMjguQ2owS0NRanc2S3VuQmhEeEFSSXNBS0ZVR3M4M1JPWmxOalFhUTczNXJfeXBiUkFIMUdXVU1jdEN4d2hQSnVjUlcwRTBfeWRRUWNDLTc4Z2FBa3NlRUFMd193Y0I.*_gcl_au*ODcxNTY5NDY4LjE2OTMwNDU0MjU.#from-the-backend) to interact with the gmail api??

I am simply missing this {id} though seems like I should not need it somehow. Is there another endpoint that simply uses my access token or is there a library to parse the access token for the {id} somehow?

I was [reading this article](https://auth0.com/docs/secure/tokens) as well trying to parse the access token. When I use the website it links([jwt.io](http://jwt.io)), it says invalid access token, BUT when I cut/paste the json to generate the token, it gives me an accesstoken just fine. I don’t understand how auth0 is giving an access token that can’t be parsed when there is docs talking about accesstoken. This is so confusing here.

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [September 6, 2023, 11:41pm UTC](https://community.auth0.com/t/confusion-on-userinfo-vs-api-v2-users-id-apis/115195/3 "2023-09-06T23:41:01Z")

</div>

Hey there @dean2 sorry for the delayed response here!

> [@dean2](#):
>
> I am simply missing this {id} though seems like I should not need it somehow. Is there another endpoint that simply uses my access token or is there a library to parse the access token for the {id} somehow?

The `{id}` is equivalent to the `sub` claim in either an ID or access token.

> [@dean2](#):
>
> I was [reading this article](https://auth0.com/docs/secure/tokens?_gl=1*1lxzj3w*_gcl_aw*R0NMLjE2OTIxNDExMTMuQ2p3S0NBand4T3ltQmhBRkVpd0Fub2RCTEg4b3FNWW9NWExtVF9EX2FJY2taQk9EUGllR2ZrVEtFOVJhUVlTZU5vai1ucllJc0VyMzlob0NiSUFRQXZEX0J3RQ..*_gcl_au*OTc3MDMzNTg1LjE2ODk2MTgyMTY.) as well trying to parse the access token. When I use the website it links([jwt.io](http://jwt.io)), it says invalid access token, BUT when I cut/paste the json to generate the token, it gives me an accesstoken just fine. I don’t understand how auth0 is giving an access token that can’t be parsed when there is docs talking about accesstoken. This is so confusing here.

It’s possible you are receiving an opaque access token if you aren’t passing an `audience` param in the `/authorize` request - The following FAQ(s) may be helpful:

[https://community.auth0.com/t/why-is-my-access-token-not-a-jwt-opaque-token/31028](https://community.auth0.com/t/why-is-my-access-token-not-a-jwt-opaque-token/31028)

[https://community.auth0.com/t/what-is-the-audience/71414](https://community.auth0.com/t/what-is-the-audience/71414)

---

<div class="post-metadata">

**Author:** ![dean2](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dean2/32/35668_2.png) [@dean2](https://community.auth0.com/u/dean2)\
**Post date:** [September 13, 2023, 6:44pm UTC](https://community.auth0.com/t/confusion-on-userinfo-vs-api-v2-users-id-apis/115195/4 "2023-09-13T18:44:51Z")

</div>

awesome info!! thank you

Adding audience param to /authorize, I got access denied. That seems odd as docs say it can be anything. Oh, I found another doc and added the management api id from my dashboard and now I get code and state on the callback. \*\*I seem to recall the code should be a JWT token? but it is not even after doing the audience? \*\*

In addition, (perhaps I should open a new question though it seems so related and part of same thread?) Is there no way to get the ‘sub’ as part of the callback with the token to eliminate a remote call OR to get the google oauth token as part of my next call to get the sub?

It seems very odd that I have to

1. receive callback
2. call code to tokens /oauth/token - for web application (myapp)
3. call user api to get the ‘sub’ - /userinfo
4. call remote to get access token to access mgmt api - /oauth/token - for machine to machine (myapp)
5. call mgmt api to get the google auth token - /api/v2/users/{userId or sub}’
6. call a google api to get an api access token(I think - trying to figure this out)
7. finally call the gmail api to do our business operation stuff

It would be nice to eliminate steps 2 and 3 and 4 and 5 so I just have a single remote call. or am I forced to do all those calls? I can probably put call #5 on a loop I guess every 24 hours to refresh it to be ready for anyone to call into the server. It seems like #5 data should be able to come from the #3 request but does not seem to be there?

It is odd to me that I had to create TWO apps in auth0 when I just have one server cluster called myapp. I had to create a web appliation and a machine to machine so my cluster has two app ids in auth0 when I would much prefer to have just 1 for less configuration per environment.

thanks,  
Dean

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [September 13, 2023, 9:59pm UTC](https://community.auth0.com/t/confusion-on-userinfo-vs-api-v2-users-id-apis/115195/5 "2023-09-13T21:59:33Z")

</div>

Happy to help!

> [@dean2](#):
>
> call user api to get the ‘sub’

The `sub` claim is available in a user’s access token and/or ID token so you shouldn’t need to make any additional call.

> [@dean2](#):
>
> - call mgmt api to get the google auth token
> - call a google api to get an api access token(I think - trying to figure this out)

You’ll want to take a look at this documentation regarding [Identity Provider Access Tokens](https://auth0.com/docs/secure/tokens/access-tokens/identity-provider-access-tokens) - A user’s profile will have an `Identities` array with the IDP access tokens.

 ![Screenshot 2023-09-13 at 2.51.25 PM](https://global.discourse-cdn.com/auth0/original/3X/f/4/f47ca07ce68e8266188e2fc29c82a40b530dd382.png)

---

<div class="post-metadata">

**Author:** ![dean2](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dean2/32/35668_2.png) [@dean2](https://community.auth0.com/u/dean2)\
**Post date:** [September 14, 2023, 9:07am UTC](https://community.auth0.com/t/confusion-on-userinfo-vs-api-v2-users-id-apis/115195/6 "2023-09-14T09:07:21Z")

</div>

> [@ty.frith](#):
>
> u’ll want to take a look at thi

@ty.frith odd, I do not see identities in the documentation for /userinfo endpoint → [Auth0 Documentation - Auth0 Docs](https://auth0.com/docs/api/authentication#get-user-info)

Isn’t that endpoint returning the user profile you talk about? (If so, I could skip then getting a mgmt api token and then calling into that api for user profile when I already called into the other one for user profile) however the docs only list these fields →

> {  
> “sub”: “248289761001”,  
> “name”: “Jane Josephine Doe”,  
> “given\_name”: “Jane”,  
> “family\_name”: “Doe”,  
> “middle\_name”: “Josephine”,  
> “nickname”: “JJ”,  
> “preferred\_username”: “j.doe”,  
> “profile”: “[http://exampleco.com/janedoe](http://exampleco.com/janedoe)”,  
> “picture”: “[http://exampleco.com/janedoe/me.jpg](http://exampleco.com/janedoe/me.jpg)”,  
> “website”: “[http://exampleco.com](http://exampleco.com)”,  
> “email”: “[janedoe@exampleco.com](mailto:janedoe@exampleco.com)”,  
> “email\_verified”: true,  
> “gender”: “female”,  
> “birthdate”: “1972-03-31”,  
> “zoneinfo”: “America/Los\_Angeles”,  
> “locale”: “en-US”,  
> “phone\_number”: “+1 (111) 222-3434”,  
> “phone\_number\_verified”: false,  
> “address”: {  
> “country”: “us”  
> },  
> “updated\_at”: “1556845729”  
> }

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [September 14, 2023, 10:43pm UTC](https://community.auth0.com/t/confusion-on-userinfo-vs-api-v2-users-id-apis/115195/7 "2023-09-14T22:43:54Z")

</div>

Hey @dean2 !

> [@dean2](#):
>
> Isn’t that endpoint returning the user profile you talk about?

I was referring to the `/api/v2/users` endpoint (Management API) referred to in Identity Provider Access Tokens [documentation](https://auth0.com/docs/secure/tokens/access-tokens/identity-provider-access-tokens?_gl=1*52i1bu*_gcl_aw*R0NMLjE2OTIxNDExMTMuQ2p3S0NBand4T3ltQmhBRkVpd0Fub2RCTEg4b3FNWW9NWExtVF9EX2FJY2taQk9EUGllR2ZrVEtFOVJhUVlTZU5vai1ucllJc0VyMzlob0NiSUFRQXZEX0J3RQ..*_gcl_au*OTc3MDMzNTg1LjE2ODk2MTgyMTY.). That is the only way you’ll be able to retrieve an external IDP access token for a user.

Hope this helps to clarify!

---

<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:** [September 28, 2023, 10:44pm UTC](https://community.auth0.com/t/confusion-on-userinfo-vs-api-v2-users-id-apis/115195/8 "2023-09-28T22:44:31Z")

</div>

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