Python中API的OAuth2授权

时间:2018-03-08 03:18:59

标签: python api authentication oauth-2.0 credentials

我正在尝试通过Manheim公司使用Python 3对API进行OAuth2授权。

文档说明“现在支持'客户端凭据'和'资源所有者'授权类型,此处详细说明了请求令牌所需的更改。”以下是API的文档:http://developer.manheim.com/#/authentication

我使用以下链接作为指南,但无济于事: https://requests-oauthlib.readthedocs.io/en/latest/oauth2_workflow.html#backend-application-flow

他们为我提供了客户端ID和客户端密码。我收到以下错误:

MissingTokenError: (missing_token) Missing access token parameter.

我试过这个:

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)

我也试过这个:

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)

我尝试过其他技术但没有成功。我究竟做错了什么?我需要做什么才能访问API?

我感谢所有人的帮助!

1 个答案:

答案 0 :(得分:2)

结果: 通过与管理API的开发人员团队联系来自行修复。我使用了错误的端点。

我将token_url更改为以下内容:

token_url = 'https://api.manheim.com/oauth2/token.oauth2'
相关问题