Commit 8e438cbe authored by Simo Sorce's avatar Simo Sorce Committed by Simo Sorce

Always augment claims if defaults are provided

Signed-off-by: 's avatarSimo Sorce <simo@redhat.com>
parent a03a0360
......@@ -155,7 +155,7 @@ class JWT(object):
"""Creates a JWT object.
:param header: A dict or a JSON string with the JWT Header data.
:param claims: A dict or a string withthe JWT Claims data.
:param claims: A dict or a string with the JWT Claims data.
:param jwt: a 'raw' JWT token
:param key: A (:class:`jwcrypto.jwk.JWK`) key to deserialize
the token. A (:class:`jwcrypto.jwk.JWKSet`) can also be used.
......@@ -163,7 +163,7 @@ class JWT(object):
:param default_claims: An optional dict with default values for
registred claims. A None value for NumericDate type claims
will cause generation according to system time. Only the values
fro RFC 7519 - 4.1 are evaluated.
from RFC 7519 - 4.1 are evaluated.
:param check_claims: An optional dict of claims that must be
present in the token, if the value is not None the claim must
match exactly.
......@@ -224,6 +224,10 @@ class JWT(object):
@claims.setter
def claims(self, c):
if self._reg_claims and not isinstance(c, dict):
# decode c so we can set default claims
c = json_decode(c)
if isinstance(c, dict):
self._add_default_claims(c)
self._claims = json_encode(c)
......
......@@ -1036,6 +1036,18 @@ class TestJWT(unittest.TestCase):
# Correct
jwt.JWT(jwt=token, key=key, check_claims={"testclaim": "test"})
def test_claim_params(self):
key = jwk.JWK(**E_A2_key)
default_claims = {"iss": "test", "exp": None}
string_claims = '{"string_claim":"test"}'
t = jwt.JWT(A1_header, string_claims, default_claims=default_claims)
t.make_encrypted_token(key)
token = t.serialize()
# Check default_claims
jwt.JWT(jwt=token, key=key, check_claims={"iss": "test", "exp": None,
"string_claim": "test"})
class ConformanceTests(unittest.TestCase):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment