Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OAuth2 authorization for API in Python

I'm trying to use OAuth2 authorization for an API through the company Manheim using Python 3.

The documentation states "The 'Client Credentials' and 'Resource Owner' grant types are both supported now and required changes to request a token are detailed here." Here is the documentation to the API: http://developer.manheim.com/#/authentication

I've used the following link as a guide but to no avail: https://requests-oauthlib.readthedocs.io/en/latest/oauth2_workflow.html#backend-application-flow

They've provided me with a client id and client secret. I'm receiving the following error:

MissingTokenError: (missing_token) Missing access token parameter.

I've tried this:

from oauthlib.oauth2 import BackendApplicationClient

client_id = 'my_id'
client_secret = 'my_secret'
token_url = 'https://sandbox.api.manheim.com/oauth2/token.oauth2'

client = BackendApplicationClient(client_id=client_id)
oauth = OAuth2Session(client=client)
token = oauth.fetch_token(token_url=token_url, 
client_id=client_id,client_secret=client_secret)

I've also tried this:

from oauthlib.oauth2 import BackendApplicationClient
from requests.auth import HTTPBasicAuth

client_id = 'my_id'
client_secret = 'my_secret'
token_url = 'https://sandbox.api.manheim.com/oauth2/token.oauth2'

auth = HTTPBasicAuth(client_id, client_secret)
client = BackendApplicationClient(client_id=client_id)
oauth = OAuth2Session(client=client)
token = oauth.fetch_token(token_url=token_url, auth=auth)

I've tried other techniques but have had no success. What am I doing wrong? What do I need to do access the API?

I appreciate any and all help!

like image 824
ant_sol Avatar asked Mar 08 '18 03:03

ant_sol


1 Answers

RESULT: Fixed it myself by reaching out to the developer team managing the API. I was using the wrong endpoint.

I changed token_url to the following:

token_url = 'https://api.manheim.com/oauth2/token.oauth2'
like image 110
ant_sol Avatar answered Nov 06 '22 22:11

ant_sol