【问题标题】:Error on Configuring Django-oauth-plus配置 Django-oauth-plus 时出错
【发布时间】:2014-05-23 05:32:05
【问题描述】:

当我尝试 docs 中的示例时,我收到 400 错误

settings.py
INSTALLED_APPS = (
'oauth_provider',
'django.contrib.auth',
)

OAUTH_SIGNATURE_METHODS = ['hmac-sha1',]

当我这样做时

>>> from oauth_provider.models import Resource, Consumer
>>> resource = Resource(name='photos', url='/oauth/photo/')
>>> resource.save()
>>> CONSUMER_KEY = 'dpf43f3p2l4k3l03'
>>> CONSUMER_SECRET = 'kd94hf93k423kf44'
>>> consumer = Consumer(key=CONSUMER_KEY, secret=CONSUMER_SECRET,
...                     name='http://127.0.0.1:9000', user=jane)
>>> consumer.save()


>>> from django.test.client import Client
>>> c = Client()

>>> import time
>>> parameters = {
...     'oauth_consumer_key': CONSUMER_KEY,
...     'oauth_signature_method': 'PLAINTEXT',
...     'oauth_signature': '%s&' % CONSUMER_SECRET,
...     'oauth_timestamp': str(int(time.time())),
...     'oauth_nonce': 'requestnonce',
...     'oauth_version': '1.0',
...     'oauth_callback': 'http://127.0.0.1:9000/request_token_ready',
...     'scope': 'photos', 
... }
>>> response = c.get("/oauth/request_token/", parameters)
>>> response.status_code

    400

我在配置中遗漏了什么吗?我找不到有关如何执行此操作的好的文档?

【问题讨论】:

  • 你解决了这个问题?我也有同样的情况,不知道怎么解决。

标签: django api authentication oauth-2.0 oauth-provider


【解决方案1】:

我也在同样的问题上苦苦挣扎,然后在OAuth's siterauthfollowed the steps 尝试了推荐的 Python 库,并获得了 request_token 和其他所需的参数。

我注意到它自动使用 HMAC-SHA1 对签名进行编码,我认为这是您想要的,因为您在顶部提到了 OAUTH_SIGNATURE_METHODS 变量。

希望对某人有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-02
    • 2023-03-06
    相关资源
    最近更新 更多