# Access token from native app used to auth API request

**URL:** <https://community.auth0.com/t/access-token-from-native-app-used-to-auth-api-request/75710>\
**Category:** Get Help\
**Created:** [January 2, 2022, 7:02pm UTC](https://community.auth0.com/t/access-token-from-native-app-used-to-auth-api-request/75710 "2022-01-02T19:02:29Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![campme.dev](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/campme.dev/32/34123_2.png) [@campme.dev](https://community.auth0.com/u/campme.dev)\
**Post date:** [January 2, 2022, 7:02pm UTC](https://community.auth0.com/t/access-token-from-native-app-used-to-auth-api-request/75710/1 "2022-01-02T19:02:29Z")

</div>

I have a native app (react native) and API in go. Separately the authorization is working fine. My problem is when I try to use an access token from a native app and send it to API via an authorization header. The server is responding with an invalid token.

My use-case is that only logged-in user should be able to use gql server. Later I would add some permissions/roles to restrict mutations/queries further.

I assumed while working in the same account all APIs and applications can exchange tokens for validations. Is that assumption correct? What am I missing?

Let me add I use Development mode.

FYI I tried following your tutorials but with no luck.

---

<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:** [January 5, 2022, 9:05pm UTC](https://community.auth0.com/t/access-token-from-native-app-used-to-auth-api-request/75710/3 "2022-01-05T21:05:08Z")

</div>

Hi @campme.dev

Welcome to the Auth0 Community!

> [@campme.dev](#):
>
> The server is responding with an invalid token.

Can you post the whole error? Is there a message about why it is being rejected? Also, can you please post an example token payload? You can use [jwt.io](http://jwt.io) to decode the token (please omit sensitive data).

---

<div class="post-metadata">

**Author:** ![campme.dev](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/campme.dev/32/34123_2.png) [@campme.dev](https://community.auth0.com/u/campme.dev)\
**Post date:** [January 6, 2022, 6:16pm UTC](https://community.auth0.com/t/access-token-from-native-app-used-to-auth-api-request/75710/4 "2022-01-06T18:16:28Z")

</div>

Hi!  
@dan.woda Thanks for the answer!

For the API in Go, I used 1 to 1 code from your example [auth0-golang-api-samples/jwt.go at master · auth0-samples/auth0-golang-api-samples · GitHub](https://github.com/auth0-samples/auth0-golang-api-samples/blob/master/01-Authorization-RS256/middleware/jwt.go) so I only get a generic error from line 96 `"Failed to validate JWT."`

The token payload I get from my native app:  
{  
“given\_name”: “Test”,  
“family\_name”: “Testowski”,  
“nickname”: “campme.test”,  
“name”: “Test Testowski”,  
“picture”: “[https://lh3.googleusercontent.com/a/121AATXAJzGoFEI8A7cGreIhDWiBPC-S0Z4BEEFik2-2u0l=s96-c](https://lh3.googleusercontent.com/a/121AATXAJzGoFEI8A7cGreIhDWiBPC-S0Z4BEEFik2-2u0l=s96-c)”,  
“locale”: “en-GB”,  
“updated\_at”: “2021-12-30T19:04:05.487Z”,  
“iss”: “[https://dev-km36il0j.us.auth0.com/](https://dev-km36il0j.us.auth0.com/)”,  
“sub”: “google-oauth2|110114067294556416841”,  
“aud”: “P1wH4FLJkuDl90gqUYW2qWXXDVSnYBKm”,  
“iat”: 1641492730,  
“exp”: 1001641492729,  
“at\_hash”: “0\_rX1A9CMfzSQfhM-oji7Q”,  
“nonce”: “nonce”  
}

I wonder if I do not omit some steps? Can I use the token from my native app directly in API?

---

<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:** [January 11, 2022, 1:02pm UTC](https://community.auth0.com/t/access-token-from-native-app-used-to-auth-api-request/75710/5 "2022-01-11T13:02:31Z")

</div>

It looks like you are sending an ID token, when you should be sending the Access token.

Can you see if there is an access token available in your native app?

---

<div class="post-metadata">

**Author:** ![campme.dev](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/campme.dev/32/34123_2.png) [@campme.dev](https://community.auth0.com/u/campme.dev)\
**Post date:** [January 19, 2022, 7:06pm UTC](https://community.auth0.com/t/access-token-from-native-app-used-to-auth-api-request/75710/6 "2022-01-19T19:06:05Z")

</div>

@dan.woda thanks, u are right I passed a wrong token, here is the payload of the correct one

```auto
{
  "iss": "https://dev-km36ixxx.us.auth0.com/",
  "sub": "google-oauth2|110114067294556416xxx",
  "aud": [
    "https://xxx/",
    "https://dev-km36ixxx.us.auth0.com/userinfo"
  ],
  "iat": 1642618826,
  "exp": 1642626026,
  "azp": "P1wH4FLJkuDl90gqUYW2qWXXDVSxxxx",
  "scope": "openid profile"
}

```

Unfortunately it still doesn’t work, any idea why?

---

<div class="post-metadata">

**Author:** ![campme.dev](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/campme.dev/32/34123_2.png) [@campme.dev](https://community.auth0.com/u/campme.dev)\
**Post date:** [January 26, 2022, 6:07pm UTC](https://community.auth0.com/t/access-token-from-native-app-used-to-auth-api-request/75710/7 "2022-01-26T18:07:04Z")

</div>

For future generations and @dan.woda , I managed to solve the issue. The scope in auth settings was the problem. I had to set up the correct `scope` for auth call to retrieve the token. Seems that the scope to retrieve user information from social logins can’t be mixed up with API specific scope.

After reading docs some more it seems that good practice is to use 2 auth calls with different scopes:

- first to retrieve tokens to login user in-app (react native app in my case)
- second call to get token for future communication with the APIs

---

<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:** [January 26, 2022, 6:13pm UTC](https://community.auth0.com/t/access-token-from-native-app-used-to-auth-api-request/75710/8 "2022-01-26T18:13:12Z")

</div>

@campme.dev,

Thanks for posting your solution!

---

<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:** [February 10, 2022, 6:13pm UTC](https://community.auth0.com/t/access-token-from-native-app-used-to-auth-api-request/75710/9 "2022-02-10T18:13:34Z")

</div>

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