# Extract id\_token in my react app

**URL:** <https://community.auth0.com/t/extract-id-token-in-my-react-app/109119>\
**Category:** Get Help\
**Tags:** login-experience, new-universal-login-experience\
**Created:** [June 13, 2023, 11:01am UTC](https://community.auth0.com/t/extract-id-token-in-my-react-app/109119 "2023-06-13T11:01:12Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![vishal.agarwal](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@vishal.agarwal](https://community.auth0.com/u/vishal.agarwal)\
**Post date:** [June 13, 2023, 11:01am UTC](https://community.auth0.com/t/extract-id-token-in-my-react-app/109119/1 "2023-06-13T11:01:12Z")

</div>

I need to extract id\_token in my react js app, but i am only able to extract access-token via getAccessTokenSilently method. Does auth0 provide any similar method for extracting id\_token in react js app?

---

<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:** [June 14, 2023, 6:49pm UTC](https://community.auth0.com/t/extract-id-token-in-my-react-app/109119/2 "2023-06-14T18:49:03Z")

</div>

Hey @vishal.agarwal!

What’s the use case here if you don’t mind elaborating a bit? If you just need the information contained in ID tokens the following should help:

> **[useAuth0 | @auth0/auth0-react](https://auth0.github.io/auth0-react/functions/useAuth0.html)**
>
> Documentation for @auth0/auth0-react

> **[Auth0 React SDK Quickstarts: Login](https://auth0.com/docs/quickstart/spa/react/01-login#show-user-profile-information)**
>
> Auth0 allows you to add authentication to your React application quickly and to gain access to user profile information. This guide demonstrates how to integrate Auth0 with any new or existing React application using the Auth0 React SDK.

---

<div class="post-metadata">

**Author:** ![vishal.agarwal](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@vishal.agarwal](https://community.auth0.com/u/vishal.agarwal)\
**Post date:** [June 15, 2023, 4:54am UTC](https://community.auth0.com/t/extract-id-token-in-my-react-app/109119/4 "2023-06-15T04:54:15Z")

</div>

The use case is, if I send id\_token in authorization than everything works fine in the laravel backend but if we send access\_token value in the authorization then auth0 middleware is giving unauthorized error.

Technicially, I should use access\_token only but I am not able to figure out why id\_token is working and access\_token is treated as unauthorized by the auth0 middleware in the laravel backend.

BTW, I am using social login and access\_token and id\_token are received after logging via gmail through auth0 react SDKs.

---

<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:** [June 15, 2023, 8:37pm UTC](https://community.auth0.com/t/extract-id-token-in-my-react-app/109119/5 "2023-06-15T20:37:48Z")

</div>

> [@vishal.agarwal](#):
>
> Technicially, I should use access\_token only but I am not able to figure out why id\_token is working and access\_token is treated as unauthorized by the auth0 middleware in the laravel backend.

Thanks for confirming - You should definitely be using the access token against your backend. I believe the issue is related to the access token being opaque as I mentioned here:

> [@Access token giving unauthorized in backend](https://community.auth0.com/t/access-token-giving-unauthorized-in-backend/109227/5):
>
> Hey @vishal.agarwal thanks for confirming - My guess is that your token is missing an audience claim and is thus [opaque](https://community.auth0.com/t/why-is-my-access-token-not-a-jwt-opaque-token/31028).

Once you include an [audience param](https://auth0.github.io/auth0-react/interfaces/AuthorizationParams.html#audience) (`AuthorizationParams` in auth0-react) in the request to get tokens the middleware should be able to verify the access token successfully. The audience is just the API identifier you use when [registering an API](https://auth0.com/docs/get-started/auth0-overview/set-up-apis) in your Auth0 dashboard.

---

<div class="post-metadata">

**Author:** ![vishal.agarwal](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@vishal.agarwal](https://community.auth0.com/u/vishal.agarwal)\
**Post date:** [June 16, 2023, 6:20am UTC](https://community.auth0.com/t/extract-id-token-in-my-react-app/109119/6 "2023-06-16T06:20:53Z")

</div>

Thank you so much. It worked fine.

---

<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:** [June 30, 2023, 6:21am UTC](https://community.auth0.com/t/extract-id-token-in-my-react-app/109119/7 "2023-06-30T06:21:34Z")

</div>

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