“Invalid signature”: oAuth provider with Django-piston

匆匆过客 提交于 2019-12-04 21:25:37

The eventual answer I found was to install a working copy of oauth_consumer into the application directory. Once I had added my consumer inside this application, everything worked as expected.

@Ricardo and anyone else having problems with this error (sorry for the "answer", I don't have commenting as of yet), I was able to avoid this error by generating my signature from following the test cases provided in piston's code. Example:

>>> from piston.oauth import *
>>> from piston.models import *
>>> consumer = Consumer.objects.get(id=1)
>>> oaconsumer = OAuthConsumer(consumer.key, consumer.secret)
>>> request = OAuthRequest.from_consumer_and_token(oaconsumer, http_url='http:
    //localhost:8000/api/oauth/request_token/')
>>> signature_method = OAuthSignatureMethod_HMAC_SHA1()
>>> request.sign_request(signature_method, oaconsumer, None)
>>> request.sign_request(signature_method, oaconsumer, None)
>>> request.parameters
{'oauth_nonce': '64379482', 'oauth_timestamp': 1297147940, 'oauth_consumer_key': u'8aZSFj3W54h8J8sCpx', 'oauth_signature_method': 'HMAC-SHA1', 'oauth_version': '1.0', 'oauth_signature': 'kGSLCZjYzAHXsa8f9sL52Kq1F2w='}

From here, just use these parameters in a browser e.g. http://localhost:8000/api/oauth/request_token/?oauth_nonce=64379482&oauth_timestamp=1297147940&oauth_consumer_key=8aZSFj3W54h8J8sCpx&oauth_signature_method=HMAC-SHA1&oauth_version=1.0&oauth_signature=kGSLCZjYzAHXsa8f9sL52Kq1F2w=

Which generates "oauth_token_secret=37VZKRV3fXRLAw5tekZD2bwnMhXqGwgx&oauth_token=LRnexBGTNC4nDXpv9M&oauth_callback_confirmed=true"

As Martin pointed out, leaving out a "/" in either the sample code or the URL will render the signature "invalid".

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!