/oath/token end-point stopped returning valid response

Hi, after some time coding on my express back-end, the /oath/token end-point suddenly stopped returning a valid response.

Expected behaviour is to receive a “data: { access_token, …}” property.

What I receive is “nonsense” characters: “data: c�@�lf��>��a���9!и鱺���’c��…”

This is the code for getting the token:

const getAuthToken = async (): Promise<string | null> => {
  const options: AxiosRequestConfig = {
    baseURL: DOMAIN,
    url: '/oauth/token',
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: {
      client_id: CLIENT_ID,
      client_secret: CLIENT_SECRET,
      audience: AUDIENCE,
      grant_type: 'client_credentials',
    },
  };

  try {
    const response = await axios(options);

    console.log(response.data);

    if (response.status === 200) return response.data.access_token;
    return null;
  } catch (err) {
    console.log(err);
    return null;
  }
};

This worked beautifully until an hour ago, when it just stopped providing the expected response.

Thank you,
Martin

Problem solved.

I had to add ‘accept-encoding: application/json’ to my Axios ‘headers’ to be rid of the problem. I still have no clue why this worked before, nor why it suddenly stopped working. But this fixed the issue.

2 Likes

Hey there @iphonelynden welcome to the community and thanks for following up on this!

I know 'content-type': 'application/json' is typically included like you have it, but I haven’t seen where accept-encoding: application/json is required so thanks for the heads up, hopefully this helps someone else in the future!

1 Like

Thanks @tyf , I have a sneaking suspicion that it is related to Axios release 1.2.0 a few days ago, but haven’t been able to confirm. They did do something to their AxiosHeaders class at least.

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