IdentityPython/pyjwkest

TypeError with base64 when using JWS.verify_compact

juanifioren opened this issue · 3 comments

Am having problems when running JWS().verify_compact(id_token, RSAKEYS):

Traceback (most recent call last):
  File "/Users/juanifioren/Projects/django-oidc-provider/oidc_provider/tests/test_token_endpoint.py", line 191, in test_idtoken_sign_validation
    id_token = JWS().verify_compact(response_dic['id_token'], RSAKEYS)
  File "/Users/juanifioren/Projects/django-oidc-provider/.tox/py27-django18/lib/python2.7/site-packages/jwkest/jws.py", line 486, in verify_compact
    jwt = JWSig().unpack(jws)
  File "/Users/juanifioren/Projects/django-oidc-provider/.tox/py27-django18/lib/python2.7/site-packages/jwkest/jwt.py", line 57, in unpack
    self.part = [b64d(p) for p in part]
  File "/Users/juanifioren/Projects/django-oidc-provider/.tox/py27-django18/lib/python2.7/site-packages/jwkest/__init__.py", line 174, in b64d
    return base64.urlsafe_b64decode(b)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/base64.py", line 112, in urlsafe_b64decode
    return b64decode(s, '-_')
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/base64.py", line 71, in b64decode
    s = _translate(s, {altchars[0]: '+', altchars[1]: '/'})
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/base64.py", line 36, in _translate
    return s.translate(''.join(translation))
TypeError: character mapping must return integer, None or unicode

Am running Django tests.
I found a post. What could be causing the problem?.

rohe commented

Which version are you running ?

24 jul 2015 kl. 23:12 skrev Roland van Laar notifications@github.com:

Am having problems when running JWS().verify_compact(id_token, RSAKEYS):

Traceback (most recent call last):
File
"/Users/juanifioren/Projects/django-oidc-provider/oidc_provider/tests/test_token_endpoint.py", line 191, in
test_idtoken_sign_validation
id_token
= JWS().verify_compact(response_dic['id_token'
], RSAKEYS)
File
"/Users/juanifioren/Projects/django-oidc-provider/.tox/py27-django18/lib/python2.7/site-packages/jwkest/jws.py", line 486, in
verify_compact

jwt

JWSig().unpack(jws)
File
"/Users/juanifioren/Projects/django-oidc-provider/.tox/py27-django18/lib/python2.7/site-packages/jwkest/jwt.py", line 57, in
unpack

self.part = [b64d(p) for p in
part]
File
"/Users/juanifioren/Projects/django-oidc-provider/.tox/py27-django18/lib/python2.7/site-packages/jwkest/init.py", line 174, in
b64d

return
base64.urlsafe_b64decode(b)
File
"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/base64.py", line 112, in
urlsafe_b64decode

return b64decode(s, '-_'
)
File
"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/base64.py", line 71, in
b64decode
s
= _translate(s, {altchars[0]: '+', altchars[1]: '/'
})
File
"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/base64.py", line 36, in
_translate

return s.translate(''
.join(translation))

TypeError: character mapping must return integer, None or unicode
I found a post. What could be causing the problem?.


Reply to this email directly or view it on GitHub.

  • Roland

”Capitalism is the extraordinary belief that the nastiest of men for the nastiest of motives will somehow work for the benefit of all" - John Maynard Keynes.

Hi @rohe,

It breaks with pyjwkest==1.0.1 in all envs py2.7 py3.4 django1.7 django1.8.

Read here: http://stackoverflow.com/questions/2229827/django-urlsafe-base64-decoding-with-decryption

I sent you a pull request. https://github.com/rohe/pyjwkest/pull/31

Greetings.

My fault @rohe, instead of using decode in your function I can encode my parameter, so:

JWS().verify_compact(id_token.encode('utf-8'), RSAKEYS)

Will fix my problem, thanks anyways.