Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SignatureMethod_HMAC_SHA1.Sign returns bytes not string in python 3 #207

Open
zags opened this issue Jun 16, 2016 · 1 comment
Open

SignatureMethod_HMAC_SHA1.Sign returns bytes not string in python 3 #207

zags opened this issue Jun 16, 2016 · 1 comment

Comments

@zags
Copy link

zags commented Jun 16, 2016

In Python 3, the return value of SignatureMethod_HMAC_SHA1.Sign is a bytes object, not a string. This is problematic for implementing 2-legged OAuth (such as under LTI, described here: https://www.imsglobal.org/specs/ltiv2p0/implementation-guide#toc-58) because the signature of a request is used in an immediate comparison against request parameters (which are strings) as opposed to sent out in a request and compared by the recipient server.

By way of example, the following code, which attempts to do a 2-legged OAuth check on an incoming Django request, will raise an erroneous Invalid Signature error from verify_request because the signature in the request is a string object and the signature returned by SignatureMethod_HMAC_SHA1.Sign is a bytes object:

oauth_server = oauth2.Server()
signature_method = Python3_SignatureMethod_HMAC_SHA1()
oauth_server.add_signature_method(signature_method)
oauth_consumer = oauth2.Consumer(consumer_key, consumer_secret)
oauth_request = oauth2.Request.from_request(
    request.method, request.build_absolute_uri(),
    headers=request.META, parameters=request.POST.dict()
)
oauth_server.verify_request(oauth_request, oauth_consumer, {})

It looks from SignatureMethod_PLAINTEXT.sign (which uses encode on the return value) that these might be intentionally bytes objects instead of unicode. Is this the case or is this an artifact of python 2's string/unicode handling?

@sudharsanmit
Copy link

python-oauth2 is broken for python3. Had the same problem.
Switched to python3-oauth2 which is a fork of python-oauth2 and added python3 compatibility.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants