GithubHelp home page GithubHelp logo

joat's Introduction

JWT OAuth Access Token

A library for generating and verifying signed JWT OAuth 2.0 access tokens.

Installation

pip install pyjoat

Usage

The JOAT library is intended to be used for issuing tokens from the OAuth 2.0 /token endpoint, as well as from resource servers to authenticate requests.

Here is an example of token generation:

import joat

def generate_hmac_salt(jwt_claims):
  return "the most secret hmac salt ever"

joat.salt_generator = generate_hmac_salt

TokenGenerator = joat.TokenGenerator("My OAuth2 Provider")

access_token = TokenGenerator.issue_token(client_id="abcd",
                                          user_id="1234",
                                          scope=["profile", "read"])

print access_token
# [line breaks added for readability only]
# eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJhYmNkIiwiaXNzIjoiTXk \
# gT0F1dGgyIFByb3ZpZGVyIiwiZXhwIjoxNDA3Mjk0NTcyLCJpYXQiOjE0MDcyOTA5NzI \
# sInNjcCI6WyJwcm9maWxlIiwicmVhZCJdLCJzdWIiOiIxMjM0In0.wgNhGiKQ0ppO0Xu \
# QhalGZmSommQROjBusCanRa_6Ydc

And one of parsing a token:

import joat

def generate_hmac_salt(jwt_claims):
  return "the most secret hmac salt ever"

joat.salt_generator = generate_hmac_salt

credentials = joat.parse_token('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJhYmNkIiwiaXNzIjoiTXkgT0F1dGgyIFByb3ZpZGVyIiwiZXhwIjoxNDA3Mjk0NTcyLCJpYXQiOjE0MDcyOTA5NzIsInNjcCI6WyJwcm9maWxlIiwicmVhZCJdLCJzdWIiOiIxMjM0In0.wgNhGiKQ0ppO0XuQhalGZmSommQROjBusCanRa_6Ydc')

print credentials
# [again, line break added for readability]
# {u'user_id': u'1234', u'authorized_scope': [u'profile', u'read'],
#  u'client_id': u'abcd', u'provider': u'My OAuth2 Provider'}

Salt Generation

Because the payload of the JWT is easily readable by anyone with access to the token, a secure HMAC salt (or secret, depending on your preferred terminology) is of the utmost importance for token security, and to avoid allowing tokens issued by a malicious third party.

To this end, PyJOAT expects you to implement salt generation on your own. The JWT claims are passed into the salt generation method so that you may use the payload data to lookup or generate the salt for the client-user-scope combination.

You may also pass a jti to the token generation method to augment the salt generation or otherwise keep track of the tokens you generate.

access_token = TokenGenerator.issue_token(client_id="abcd",
                                          user_id="1234",
                                          scope=["profile", "read"],
                                          jti="your_token_id")

joat's People

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.