Spotify api refresh token doesn't return a token with refresh_token

Viewed 40

After the token is expired, I try to get a new token with this code:

const buffer = Buffer.from(
  `${String(CLIENT_ID)}:${String(CLIENT_SECRET)}`
).toString("base64");

const params: Record<DataParamName, string> = {
  grant_type: "refresh_token",
  refresh_token: String(refresh_token),
};

const data = new URLSearchParams(params).toString();

const result = await axios({
  method: "post",
  url: "https://accounts.spotify.com/api/token",
  data,
  headers: {
    "content-type": "application/x-www-form-urlencoded",
    Authorization: `Basic ${buffer}`,
  },
});

The request is successful but returns.

{
  access_token: 'BQBok7CuDi0nYQ041YUStlbvDNbTzJzGbKax52JQcCeOIxqOijonqR8RTqxNhjgW0XYZkSolrYihkUsLxJV5L-L-x6Mv4MBngd7kZihvfZYXuPUG3DLV1Wx_j7Tki3pZe5Pjfo4bRt2rLnFTiR8ZjZxXu5slzofTtFVtw3DGKofyWdLj6VKfzIl_aOvVgqXEozgUF4qRwpA3v5zLbkyhYqCJDBUYJUjBrwTGrA',
  token_type: 'Bearer',
  expires_in: 3600,
  scope: 'playlist-read-private user-follow-read user-read-email user-read-private',
}

so next time I request a new token, the request doesn't work because the refresh_token is missing

Do you know what can be my mistake?

0 Answers
Related