# Make Request to Auth0 api from react native app

**URL:** <https://community.auth0.com/t/make-request-to-auth0-api-from-react-native-app/68746>\
**Category:** Get Help\
**Created:** [August 28, 2021, 6:09pm UTC](https://community.auth0.com/t/make-request-to-auth0-api-from-react-native-app/68746 "2021-08-28T18:09:53Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![schoenbl](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/schoenbl/32/13173_2.png) [@schoenbl](https://community.auth0.com/u/schoenbl)\
**Post date:** [August 28, 2021, 6:09pm UTC](https://community.auth0.com/t/make-request-to-auth0-api-from-react-native-app/68746/1 "2021-08-28T18:09:53Z")

</div>

I have a react native app authenticated with Auth0.

I have an API that uses react native.

When a user signs in, i take the `accessToken` that is given for that user, and I make request to the API with the `accessToken` set as the authorization header.

I do so like this:

```auto
const requestHeader = {
        headers: {
            Authorization: `Bearer ${accessToken}`,
        }
    }

axios.post(API_BASE + '/api/example/', requestHeader)

```

The `accessToken` is something short like this: `aBQdd0kOvb1pNj-9XDj_C6bKWkMg9D_q`

When I try to validate the request with the API, I get this error:

```auto
UnauthorizedError: jwt malformed

```

I know i’m getting this error because the access token isn’t a JWT.

I’m validating in the API like this:

```auto
exports.checkJwt = jwt({
    secret: jwksRsa.expressJwtSecret({
        cache: true,
        rateLimit: true,
        jwksRequestsPerMinute: 5,
        jwksUri: 'https://dev-0p1doq9r.auth0.com/.well-known/jwks.json'
  }),
  audience: 'ddasdsfasdfasd',
  issuer: 'safsdfasdfasdfafsdf',
  algorithms: ['RS256']
});

```

I know that `accessToken` needs to be transformed into a JWT on the client, BUT HOW? I have not found any documentation for this; I have also not found what other properties need to be included in the JWT for validation.

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [August 30, 2021, 9:17pm UTC](https://community.auth0.com/t/make-request-to-auth0-api-from-react-native-app/68746/3 "2021-08-30T21:17:18Z")

</div>

Hi @schoenbl,

Welcome back to the Auth0 Community!

Take a look at this resource:

[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)

---

<div class="post-metadata">

**Author:** ![schoenbl](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/schoenbl/32/13173_2.png) [@schoenbl](https://community.auth0.com/u/schoenbl)\
**Post date:** [August 31, 2021, 6:05am UTC](https://community.auth0.com/t/make-request-to-auth0-api-from-react-native-app/68746/4 "2021-08-31T06:05:32Z")

</div>

Hi Dan! Thanks for your response! That doesn’t seem to be working for me.

This is how I’m using the Auht0 constructor from the React Native Auth0 SDK:

```auto
import Auth0 from 'react-native-auth0';
const auth0 = new Auth0({
    audience: "https://api.thepodapp.com",
    domain: 'dev-0p1doq9r.auth0.com',
    clientId: 'LOfg18i9rCofQQadginNQVlDz8zF7PXI',
});

export const signInAsync = (callback) => {
    auth0
        .webAuth
        .authorize({scope: 'openid profile email'})
        .then(credentials => callback(credentials))
        .catch(err => callback(null, err))
}

```

When I do that, I still receive and opaque token. Should I be receiving a JWT when I do this?

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [August 31, 2021, 3:09pm UTC](https://community.auth0.com/t/make-request-to-auth0-api-from-react-native-app/68746/5 "2021-08-31T15:09:35Z")

</div>

Have you registered an API in the Auth0 dashboard that corresponds with that audience?

E.G.:

![image](https://global.discourse-cdn.com/auth0/original/3X/6/3/63ef0365d82dabd794033472e262e35872ca4392.png)

---

<div class="post-metadata">

**Author:** ![schoenbl](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/schoenbl/32/13173_2.png) [@schoenbl](https://community.auth0.com/u/schoenbl)\
**Post date:** [September 3, 2021, 4:58am UTC](https://community.auth0.com/t/make-request-to-auth0-api-from-react-native-app/68746/6 "2021-09-03T04:58:29Z")

</div>

Hi Dan, thanks for the response. I really appreciate your help.

Yes, I have made the corresponding API in the Auth0 dashboard:

 ![Screen Shot 2021-09-02 at 9.57.19 PM](https://global.discourse-cdn.com/auth0/original/3X/a/5/a556cfc058e130b01c823b2d0afed6c621bcce3b.png)

Any other ideas on what the issue might be?

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [September 3, 2021, 4:35pm UTC](https://community.auth0.com/t/make-request-to-auth0-api-from-react-native-app/68746/7 "2021-09-03T16:35:18Z")

</div>

Can you try passing the audience param to your authorize method?

```auto
authorize( {
  ...,
  audience:"https://test-api"
} )

```

---

<div class="post-metadata">

**Author:** ![schoenbl](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/schoenbl/32/13173_2.png) [@schoenbl](https://community.auth0.com/u/schoenbl)\
**Post date:** [September 5, 2021, 6:30pm UTC](https://community.auth0.com/t/make-request-to-auth0-api-from-react-native-app/68746/8 "2021-09-05T18:30:17Z")

</div>

This worked! Thank you! Should the documentation be updated?

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [September 8, 2021, 5:12pm UTC](https://community.auth0.com/t/make-request-to-auth0-api-from-react-native-app/68746/9 "2021-09-08T17:12:57Z")

</div>

It sounds like that would be helpful. I can’t find any references to passing the audience when you create the Auth0 object, did you see that recommended somewhere? I’d like to recommend an update.

---

<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 23, 2021, 5:13pm UTC](https://community.auth0.com/t/make-request-to-auth0-api-from-react-native-app/68746/10 "2021-09-23T17:13:49Z")

</div>

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