Skip to main content

Authorize user via jwt

Project description


A Python implementation of acquiring, authorizing user from jwt token. designed to work for any request entity from flask,django,tornado frameworks.


Install with pip:

$ pip install jwt_user


>>> import jwt_user
>>> payload = {'username': 'test'}
>>> token = jwt_user.generate_token(payload)
>>> request = jwt_user.generate_request(token)
>>> user = jwt_user.get_jwt_user(request)
>>> user
>>> user.username
>>> #Second usage
>>> import tornado
>>> BaseRequestHandler = tornado.web.RequestHandler
>>> class MainHandler(BaseRequestHandler):
...     @jwt_user.authorized_user
...     def get(self):
...         self.write('Hello, Authorized user')
>>> class MainUserHandler(BaseRequestHandler):
...     @jwt_user.authorized_user
...     def get(self):
...         user = jwt_user.get_jwt_user(self.request)
...         self.write('Hello, {}'.format(user.username))
>>> os.environ['JWT_EXPIRATION_DELTA'] = '3400'
>>> os.environ['JWT_PRIVATE_KEY'] = 'some random hexa private text'
>>> os.environ['JWT_SECRET_KEY'] = 'some random hexa secret text'
>>> os.environ['JWT_AUTH_HEADER'] = 'Authorization'
>>> os.environ['JWT_AUTH_HEADER_PREFIX'] = 'Bearer'
>>> def make_app():
...     user_valid_fields = {'username', 'user_id', 'token'}
...     jwt_user.set_user_valid_fields(user_valid_fields)
...     application = tornado.web.Application([
...     (r'/', MainHandler),
...     (r'/user_page', MainUserHandler)])
...     return application



View the full docs online at


You can run tests from the project root after cloning with:

$ make smoke

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for jwt-user, version 0.0.9
Filename, size File type Python version Upload date Hashes
Filename, size jwt_user-0.0.9-py3-none-any.whl (6.0 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size jwt_user-0.0.9.tar.gz (4.1 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page