verify_signed_jwt.py Source

#!/usr/bin/env python3
import os
import json
import pprint
from jwcrypto.jwk import JWK
from jwcrypto.jwt import JWT
printer = pprint.PrettyPrinter(indent=4, width=66)
pformat = printer.pformat
def main():
    with open('example_credential_scanned.jose', 'r') as tokenfile:
        token = JWT.from_jose_token(tokenfile.read())
    with open('authority_key.pub', 'r') as pubkeyfile:
        pubkey = JWK.from_json(pubkeyfile.read())
    token.validate(pubkey)
    print("Header: ", pformat(json.loads(token.header)))
    print("Claims: ", pformat(json.loads(token.claims)))
if __name__ == '__main__':
    main()