Reputation: 619
I am getting {"error":"invalid_client","error_description":"client authentication failed"} 401 response. I did manage to get a user consent (docs: https://developer.ebay.com/api-docs/static/oauth-authorization-code-grant.html) by accessing the url manually and logging in to my account:
import requests, urllib, base64
my_AppID = "someAppID"
my_Ru_Name = "someRuName"
scope = "https://api.ebay.com/oauth/api_scope/sell.fulfillment"
scope = urllib.parse.quote_plus(scope)
url = f"""https://auth.ebay.com/oauth2/authorize?
client_id={my_AppID}&
redirect_uri={my_Ru_Name}&
response_type=code&
scope={scope}&"""
I printed the url string and accessed it in the browser, logged in and "consented". This page said "Authorization successfully completed." so I took the code value from the new redirected page url. After this I was unable to exchange the authorization code for a User access token:
my_CertID = "someCertID"
client_id = base64.b64encode(my_AppID.encode())
client_secret = base64.b64encode(my_CertID.encode())
auth_string = "Basic " + client_id.decode() + ":" + client_secret.decode()
consent_code = "v%521.1%25i..................jYw" # from the page's link after logging in
consent_code = urllib.parse.quote_plus(code)
headers = {"Content-Type": "application/x-www-form-urlencoded", "Authorization": auth_string}
data = {"grant_type": "authorization_code", "code": consent_code , "redirect_uri": Ru_Name}
url_token = "https://api.ebay.com/identity/v1/oauth2/token"
resp = requests.post(url_token, headers=headers, data=data)
print(resp.text)
# the response I get:
{"error":"invalid_client","error_description":"client authentication failed"}
What am I doing wrong? Is it the request part? The encoding?
I am kinda new to all this so thanks in advance!
Upvotes: 1
Views: 1208
Reputation: 2650
The consent_code is url encoded. You need to decode it (use online service).
url encoded the code looks like this: v%5E1.1%23i%5E1%23f%5E0%23r... - which is wrong. After url decode it looks like this: v^1.1#i^1#f^0#r^1#p^3#I^3...
Upvotes: 0
Reputation: 1
I was having problems but have now got them sorted and use a drupal module to get my access token. I have made this available as a service here at apiauth.net. Let me know if it is any help.
Upvotes: 0
Reputation: 1
try following:
client_id = my_AppID
client_secret = my_CertID
auth_string = "Basic " + base64.b64encode(client_id + ":" + client_secret)
Upvotes: 0