# React native PKCE expo authorization troubles

**URL:** <https://community.auth0.com/t/react-native-pkce-expo-authorization-troubles/70611>\
**Category:** Get Help\
**Tags:** login\
**Created:** [October 1, 2021, 8:39am UTC](https://community.auth0.com/t/react-native-pkce-expo-authorization-troubles/70611 "2021-10-01T08:39:19Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Espenbfo](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@Espenbfo](https://community.auth0.com/u/Espenbfo)\
**Post date:** [October 1, 2021, 8:39am UTC](https://community.auth0.com/t/react-native-pkce-expo-authorization-troubles/70611/1 "2021-10-01T08:39:19Z")

</div>

I have been trying to set up the PKCE authorization with an expo react native application. This went well, up until I tried to fetch the access token from the /oauth/token endpoint.

The relevant code:

```auto
import * as AuthSession from 'expo-auth-session';
import { pkceChallenge } from 'react-native-pkce-challenge';

const authorizationEndpoint = "https://{myurl}/authorize";
const accessTokenUrl = "https://{myurl}/oauth/token";
const {codeChallenge, codeVerifier} = pkceChallenge();
const redirectUri = AuthSession.makeRedirectUri();

```

```auto
  const [request, result, promptAsync] = AuthSession.useAuthRequest(
    {
      redirectUri,
      clientId: auth0ClientId,
      codeChallenge: encodeURIComponent(codeChallenge),
      codeChallengeMethod: AuthSession.CodeChallengeMethod.S256,
      responseType: 'code',
      scopes: ['openid'],
      extraParams: {
        audience: "{myaudience}"
      }

    },
    { authorizationEndpoint }
  );

```

Here I got the response:

```auto
{
  "authentication": null,
  "error": null,
  "errorCode": null,
  "params": Object {
    "code": "f7SPGa4iMvQUBnBI",
    "state": "lCVrP2kake",
  },
  "type": "success",
  "url": "{redirectURI}?code=f7SPGa4iMvQUCnAI&state=lCVrP2kaka",
}

```

```auto
fetch(accessTokenUrl, {
          method: "POST",
          headers: { "content-type": 'application/x-www-form-urlencoded' },
          body: JSON.stringify({
            code: encodeURIComponent(result.params.code),
            redirect_uri: encodeURIComponent(redirectUri),
            client_id: encodeURIComponent(auth0ClientId),
            grant_type: encodeURIComponent('authorization_code'),
            code_verifier: encodeURIComponent(codeVerifier)
          })

```

To this I got a 401 response:

```auto
 "error": "access_denied",
 "error_description": "Unauthorized",

```

---

<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:** [October 15, 2021, 7:11pm UTC](https://community.auth0.com/t/react-native-pkce-expo-authorization-troubles/70611/3 "2021-10-15T19:11:02Z")

</div>

Hi @Espenbfo,

Welcome to the Auth0 Community!

I understand that you have been encountering errors trying to exchange for an access token with your React Native App.

First, could you please clarify whether you are using one of our [SDKs](https://auth0.com/docs/libraries)?

Next, have you taken a look at your Auth0 [Dashboard Logs](https://manage.auth0.com/#/logs) to see more details regarding the `401 Unauthorized` error?

Could you please relay the error details to me to further assist you?

Looking forward to your response.

Thank you.

---

<div class="post-metadata">

**Author:** ![miguelfeliciano](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/miguelfeliciano/32/33224_2.png) [@miguelfeliciano](https://community.auth0.com/u/miguelfeliciano)\
**Post date:** [October 26, 2022, 8:37pm UTC](https://community.auth0.com/t/react-native-pkce-expo-authorization-troubles/70611/4 "2022-10-26T20:37:03Z")

</div>

Did you ever get this resolved? We’re running into something similar and I’m wondering if expo-auth-session package is no longer working with Auth0.

We’re on Expo v44 now from v42 which was working, but v42 wasn’t supported in Expo Go anymore.

---

<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:** [December 10, 2022, 12:42am UTC](https://community.auth0.com/t/react-native-pkce-expo-authorization-troubles/70611/5 "2022-12-10T00:42:55Z")

</div>

Hi @miguelfeliciano,

Unfortunately, @Espenbfo and I could never finish troubleshooting the issue any further.

If you are encountering a similar issue, could you please see if [this solution](https://community.auth0.com/t/getting-unauthorized-access-denied-on-getting-token-using-refresh-token/88378/3) helps with your situation?

Otherwise, could you please [capture a HAR file](https://auth0.com/docs/troubleshoot/troubleshooting-tools/generate-and-analyze-har-files) and DM it to me to investigate further?

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:** [December 24, 2022, 12:43am UTC](https://community.auth0.com/t/react-native-pkce-expo-authorization-troubles/70611/6 "2022-12-24T00:43:19Z")

</div>

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