I found TimedJSONWebSignatureSerializer
and URLSafeTimedSerializer
. I wonder why those two methods exist. As a user of that library, what are reasons to chose one or the other?
What I've tried
I didn't even find TimedJSONWebSignatureSerializer
in the docs, but only something general about JSON Web Signatures.
Looking at the inheritance did not help:
TimedJSONWebSignatureSerializer
inherits fromJSONWebSignatureSerializer
URLSafeTimedSerializer
inherits fromURLSafeSerializerMixin
,TimedSerializer
Looking at the constructors, I have the impression that both might be for the same use cases, but maybe the JSON Web Signatures are standardized while the other one isn't?
Looking at usage:
from itsdangerous import TimedJSONWebSignatureSerializer, URLSafeTimedSerializer
data = {"id": 42, "op": "foobar"}
max_age_s = 123
s1 = TimedJSONWebSignatureSerializer('secret', expires_in=max_age_s)
s1_dumped = s1.dumps(data)
s1_loaded = s1.loads(s1_dumped)
s2 = URLSafeTimedSerializer('secret')
s2_dumped = s2.dumps(data)
s2_loaded = s2.loads(s2_dumped, max_age=max_age_s)
Then
>>> s1_dumped
b'eyJhbGciOiJIUzUxMiIsImlhdCI6MTU2MTEwNDU0NSwiZXhwIjoxNTYxMTA4MTQ1fQ.eyJpZCI6NDIsIm9wIjoiZm9vYmFyIn0.sux9j4OpBc7-se16WSrZvp-bll5ZeyCQR_CumSE7jPQ9-w_kTqpr0OtwhJp8S766Xt1W3fKSE-dl2z8q9ZAhzg'
>>> s2_dumped
'eyJpZCI6NDIsIm9wIjoiZm9vYmFyIn0.XQyQoQ.-6n5Jw6TWz8tsyfgagyS5_fHjAY'
>>> len(s1_dumped)
185
>>> len(s2_dumped)
66
Hence the JSON Web Signature is way longer. What do you win by having it?