cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Error when refreshing access token: "invalid_grant"

 

Hi everyone,

I'm experiencing an issue when attempting to refresh my access token using the refresh token obtained during the OAuth2 flow. Each time I send a POST request to the OAuth token endpoint to retrieve a new access token, I get the following error:

 

json
{"error": "invalid_grant", "error_description": "the provided authorization refresh token is invalid or was issued to another client"}

Below is the Python code I am using to request the new access token. Sensitive information such as client_id, client_secret, and the refresh token have been replaced for security reasons:

 

python
import requests import base64 # eBay API credentials (sensitive info replaced) CLIENT_ID = '<your-client-id>' CLIENT_SECRET = '<your-client-secret>' # Refresh token previously obtained REFRESH_TOKEN = '<your-refresh-token>' # Scope(s) I am requesting access to SCOPES = 'https://api.ebay.com/oauth/api_scope/sell.inventory https://api.ebay.com/oauth/api_scope/sell.fulfillment' # Base64-encoded client_id and client_secret auth_string = f"{CLIENT_ID}:{CLIENT_SECRET}" base64_auth_code = base64.b64encode(auth_string.encode()).decode() # eBay token endpoint TOKEN_ENDPOINT = 'https://api.ebay.com/identity/v1/oauth2/token' # Headers and data for the POST request to get the new access token headers = { 'Content-Type': 'application/x-www-form-urlencoded', 'Authorization': f'Basic {base64_auth_code}', } data = { 'grant_type': 'refresh_token', 'refresh_token': REFRESH_TOKEN, 'scope': SCOPES # If requesting multiple scopes, add them as shown here } # Send the POST request to get the tokens response = requests.post(TOKEN_ENDPOINT, headers=headers, data=data) # Check the response status if response.status_code == 200: tokens = response.json() print("New access token successfully obtained:", tokens['access_token']) print("Expires in:", tokens['expires_in'], "seconds") else: print(f"Error refreshing access token (status: {response.status_code}😞 {response.text}")
 

What I have checked:

  • The client_id, client_secret, and redirect_uri match what I registered in the eBay Developer Console.
  • The authorization code and refresh token are both recent and have not expired.
  • I am using the correct endpoint: https://api.ebay.com/identity/v1/oauth2/token.

Question: Has anyone faced this error before or knows why this might be happening? It seems that my refresh token is invalid or being rejected despite being valid when initially obtained. Any help or insights would be greatly appreciated!

Thank you in advance!

Message 1 of 1
latest reply
0 REPLIES 0