Giter VIP home page Giter VIP logo

jsontokens-py's Introduction

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

jsontokens-py's People

Contributors

shea256 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.