expo AppAuth.exchangeCodeAsync is not a function

Please provide the following:

  1. SDK Version: 37
  2. Platforms(Android/iOS/web/all): android

I have been using expo-auth-session for OAuth authentication for the BlueButton api.I have been able to get the authorization code via useAuthRequest function.

const [request, response, promptAsync] = useAuthRequest(
    {
      issuer: "https://sandbox.bluebutton.cms.gov",
      clientId: "kbG5kRRrnQZuDqUri65x5bYcKGMUaV318BFT5rws",
      scopes: ["profile"],

      clientSecret:
        "pwpmPPvJdtNyIo8ilskmzkcPghvcAWBPgm89ggfolkBWv2DUa0gPD8zB2HD7CMeNJSFegRo2f70RvvJ5haqXA8OTs8mfLc1nyd0ItA29L3YlVtQFsnuM2kpiiZ66taYN",
      // For usage in managed apps using the proxy
      redirectUri: makeRedirectUri({ useProxy: false }),
      state: "<state>",
    },
    discovery
  );

in response I am getting json object

Object {
  "error": null,
  "errorCode": undefined,
  "params": Object {
    "code": "LwdjiafqqOj9KDPT7u0EOvBfeiKHuA",
    "state": "<state>",
  },
  "type": "success",
  "url": "exp://192.168.1.107:19000?code=LwdjiafqqOj9KDPT7u0EOvBfeiKHuA&state=%3Cstate%3E",
}

now I want to obtain the token via this authorization code,and I cant find any function in expo-auth-session API to obtain token after receiving the authorization code.

found a function on https://docs.expo.io/guides/authentication/

const { accessToken } = await AuthSession.exchangeCodeAsync(
  {
    clientId: request?.clientId,
    redirectUri,
    code: result.params.code,
    extraParams: {
      // You must use the extraParams variation of clientSecret.
      // Never store your client secret on the client.
      client_secret: 'CLIENT_SECRET',
    },
  },
  { tokenEndpoint: 'https://www.strava.com/oauth/token' }
);

but upon using this function getting

undefined is not a function (near '...AuthSession.exchangeCodeAsync...')

can anybody explain is it possible via expo-auth-session to obtain token or what is a standard flow to obtain token upon receiving the authorization code.

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