Skip to content

blockstack-packages/jsontokens-py

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JSON Tokens

CircleCI PyPI PyPI PyPI Slack

Installation

$ pip install jsontokens

Importing

>>> from jsontokens import TokenSigner, TokenVerifier, decode_token

Signing Tokens

>>> token_signer = TokenSigner()
>>> payload = {"issuedAt": "1440713414.19"}
>>> token = token_signer.sign(payload, 'a5c61c6ca7b3e7e55edee68566aeab22e4da26baa285c7bd10e8d2218aa3b22901')
>>> print token
eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3N1ZWRBdCI6IjE0NDA3MTM0MTQuMTkifQ.7UpSjte-bbk0CsBgC3AJyogLKu6SGzyigFgo2qZeUN6zKHaQsBlz_pFwHkPGLmiz4yvOd5gfWu8R2BwFX55okQ

Decoding Tokens

>>> decoded_token = decode_token(token)
>>> import json
>>> print json.dumps(decoded_token, indent=2)
{
  "header": {
    "alg": "ES256", 
    "typ": "JWT"
  }, 
  "payload": {
    "issuedAt": "1440713414.19"
  }, 
  "signature": "7UpSjte-bbk0CsBgC3AJyogLKu6SGzyigFgo2qZeUN6zKHaQsBlz_pFwHkPGLmiz4yvOd5gfWu8R2BwFX55okQ"
}

Verifying Tokens

>>> token_verifier = TokenVerifier()
>>> token_is_valid = token_verifier.verify(token, '027d28f9951ce46538951e3697c62588a87f1f1f295de4a14fdd4c780fc52cfe69')
>>> print token_is_valid
True

About

Library for signing and decoding JSON Web Tokens

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages