I want to refresh my spotify oAuth tokens but my request fails and i dont get any error message
i am currently developing a react native app using supabase. I am able to sign in using the pkce flow, but i am now stuck at refreshing the spotify token.
I am receiving an error response but sadly without any further information
{"error": "invalid_request", "error_description": ""}
this is my current implementation:
class SpotifyTokenRefreshStrategy implements TokenRefreshStrategy {async refreshTokens(config: RefreshTokenConfig): Promise<void> {const url = "https://accounts.spotify.com/api/token"const clientId: string | undefined =process.env.EXPO_PUBLIC_SPOTIFY_CLIENT_IDif (!clientId) {throw new Error("Spotify client ID not found") }const data = {grant_type: "refresh_token",refresh_token: config.refreshToken,client_id: clientId, }const body = Object.entries(data) .map( ([key, value]) =>`${encodeURIComponent(key)}=${encodeURIComponent(value)}` ) .join("&")const payload = {method: "POST",headers: {"Content-Type": "application/x-www-form-urlencoded", },body: body, }try {const response = await fetch(url, payload)console.log("response", await response.json())if (!response.ok) {throw new Error(`HTTP error! status: ${response.status}`) }const json = await response.json()console.log("Spotify refresh response:", json) } catch (error) {console.error("Error:", error)throw error } }}
the client_id is defined, as well as the refresh token. I can be sure of that because when i remove or modify those parameters from the request, the error message changes to invalid client_id/refresh_token. So it seems that those two paramters are correct, but there is still an issue in the code.
the body strings looks like this:
grant_type=refresh_token&refresh_token=AQBtIQoY8tim8s5LMjkgSZBF3lxqdOH_NBL40Ha-VvhRDPb_B04hlwe7s6sw_UPZrGwrwIXmJodBehxeiqZLAqAI4SvJBW54OoP_ooVNmnt704bwCrTQybKtRpFybLq9DN0&client_id=3f122ae12969427e9807f76a43ce6350
i also have added all available scopes, because i thought maybe this is the cause of the error but it isnt.
I am really really stuck on this, so i would appreciate any help from y'all :)