Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
17 lines (15 sloc) 531 Bytes
import jws
def to_jwt(claim, algo, key):
header = {'typ': 'JWT', 'alg': algo}
return '.'.join([
jws.sign(header, claim, key)
def from_jwt(jwt, key):
"Returns the decoded claim on success, or throws exception on error"
(header, claim, sig) = jwt.split('.')
header = jws.utils.from_base64(header)
claim = jws.utils.from_base64(claim)
jws.verify(header, claim, sig, key, is_json=True)
return jws.utils.from_json(claim)