# Redirect to /authorize then it callsback with code and state then confusion

**URL:** <https://community.auth0.com/t/redirect-to-authorize-then-it-callsback-with-code-and-state-then-confusion/116212>\
**Category:** Get Help\
**Tags:** user-profile, user-management\
**Created:** [September 14, 2023, 9:56am UTC](https://community.auth0.com/t/redirect-to-authorize-then-it-callsback-with-code-and-state-then-confusion/116212 "2023-09-14T09:56:41Z")\
**Posts on this page:** 3\
**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 14, 2023, 9:56am UTC](https://community.auth0.com/t/redirect-to-authorize-then-it-callsback-with-code-and-state-then-confusion/116212/1 "2023-09-14T09:56:42Z")

</div>

I am calling /authorize which redirects to may /callback?code=xxx&state=yyy. I read this page [Get ID Tokens](https://auth0.com/docs/secure/tokens/id-tokens/get-id-tokens)

1. Is the code an id token I can validate without going remote? The libs in that url referenced can’t seem to validate that token since it is not jwt.
2. Can I get ‘sub’ from this code above(the xxx)? If so, I can skip the call to /userinfo which seems a bit useless as it
3. The call to /userinfo does not return an identies array with google’s oauth tokens and the docs show that only the management api returns that(seems odd though). Is this true or is docs just missing that field? Currently, when I run, I do not see it returned but perhaps there is config to make it return more?

My GUESS: For highest security, validate the state passed from callback is the same random secure thing AND call /oauth/token and decode the JWT token. If all that is good, we are secure ‘I hope/think’.

I was able to get sub form decoding the jwt after I had the right audience and use that for fetching google’s tokens without using /userinfo now. All signups take 2 calls to auth0 for now ☹ while I was hoping just one to keep the load fast.

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [September 18, 2023, 9:44pm UTC](https://community.auth0.com/t/redirect-to-authorize-then-it-callsback-with-code-and-state-then-confusion/116212/3 "2023-09-18T21:44:54Z")

</div>

Hi @dean2,

Let me clarify that the code you received is meant to be exchanged for tokens. To do so, you will need to specify the `scope=openid` in the request and include an `audience` parameter to get a valid JWT token.

After you have exchanged the code for a token at the `/oauth/token` endpoint, you should get your Access and ID Token.

If you do not specify the `audience` parameter, the token will be opaque and can only be used with the `/userinfo` endpoint.

I recommend reviewing the following doc:

[https://auth0.com/docs/get-started/authentication-and-authorization-flow/call-your-api-using-the-authorization-code-flow](https://auth0.com/docs/get-started/authentication-and-authorization-flow/call-your-api-using-the-authorization-code-flow)

I hope the explanation is clear!

Thanks,  
Rueben

---

<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:** [October 2, 2023, 9:45pm UTC](https://community.auth0.com/t/redirect-to-authorize-then-it-callsback-with-code-and-state-then-confusion/116212/4 "2023-10-02T21:45:33Z")

</div>

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