【问题标题】:python oauth2 client issues when trying to get authorization token尝试获取授权令牌时出现python oauth2客户端问题
【发布时间】:2016-04-29 13:00:06
【问题描述】:

我正在尝试使用 OAuth2 通过 Python 将授权令牌获取到 REST API。我使用 CURL 成功,但没有使用 python。我正在使用以下文档中提供的示例: https://requests-oauthlib.readthedocs.org/en/latest/oauth2_workflow.html

以下是我的代码:

#!/usr/bin/python

import requests
import requests_oauthlib
from requests_oauthlib import OAuth2Session
from oauthlib.oauth2 import BackendApplicationClient

client_id = 'AAAAAA'
client_secret = 'BBBBBB'

client = BackendApplicationClient(client_id=client_id)
oauth = OAuth2Session(client=client)
token = oauth.fetch_token(token_url='https://example.com/as/token.oauth2', client_id=client_id, client_secret=client_secret)

print token

我收到以下错误:

oauthlib.oauth2.rfc6749.errors.InvalidClientError: (invalid_client)   client_id value doesn't match HTTP Basic username value

这是一个非常基本的 API,只需要 client_id 和 client_credentials 即可获得授权令牌。

所有信息将不胜感激。

【问题讨论】:

    标签: python rest client access-token oauth2


    【解决方案1】:

    文档指定了以下项目:

    client_id = r'your_client_id'
    client_secret = r'your_client_secret'
    redirect_uri = 'https://your.callback/uri'
    

    您所说的客户端密钥是指客户端密钥吗?

    token = oauth.fetch_token(token_url='https://example.com/as/token.oauth2', client_id=client_id, client_secret=client_secret)
    

    尝试将其更改为上述内容并试一试。使用 r'' 代替原始输入并给出令牌。

    【讨论】:

    • 谢谢!不幸的是,现在我得到 oauthlib.oauth2.rfc6749.errors.InvalidClientError: (invalid_client) 客户端不能在每个请求中使用多个身份验证方法。
    • 您是否正在尝试连接到 Microsoft Active Directory?如果不是特定的服务会有所帮助,这样我就可以缩小正在发生的事情。
    • 我的错误你要与 OAUTH2 不是 1 我已经更新了答案以反映这一点
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-06-02
    • 1970-01-01
    • 1970-01-01
    • 2020-12-31
    • 2017-01-19
    • 2020-07-12
    • 1970-01-01
    相关资源
    最近更新 更多