Skip to content

jwt.encode produces not constant JWT header in Python 3 #116

@henri-hulski

Description

@henri-hulski

After updating to 1.0.0 I found some inconsistency:
When running the following test:

def test_encode_jwt():
    import jwt
    from sys import version_info
    claims_set = {
        'sub': 'user'
    }
    key = 'secret'
    token = jwt.encode(claims_set, key)
    if version_info >= (3, 0, 0):
        token = token.decode(encoding='UTF-8')

    assert token == 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1c2VyIn0.' \
                    '8jVjALlPRYpE03sMD8kuqG9D4RSih5NjiISNZ-wO3oY'

In Python 2.7 this test passes always.
In Python 3.4 this test sometimes passes and sometimes not.
The reason is, that in Python 3 jwt.encode sometimes produce a header like:

{
  "alg": "HS256",
  "typ": "JWT"
}

This is the same like in Python 2.

But sometimes it produces a header like:

{
  "typ": "JWT",
  "alg": "HS256"
}

I didn't find out why this happens.

Regards,
Henri

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions