Skip to main content

Authorize user via jwt

Project description

jwt_user

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

Installing

Install with pip:

$ pip install jwt_user

Usage

>>> 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
'test'
>>> #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
>>>

],

Documentation

View the full docs online at https://jwt_user.readthedocs.io/en/latest/

Tests

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.

Source Distribution

jwt_user-0.0.9.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jwt_user-0.0.9-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file jwt_user-0.0.9.tar.gz.

File metadata

  • Download URL: jwt_user-0.0.9.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.4

File hashes

Hashes for jwt_user-0.0.9.tar.gz
Algorithm Hash digest
SHA256 942281cfa28ed0cac4ab1252647b9e174ebbb9ab774340c4345294c7bf632beb
MD5 23859470681a9010d9fddc8cfed1b229
BLAKE2b-256 f8f7c0480c575e74d4ad60d6907e9ae8721061fa00e4ec589b519d46547d54bd

See more details on using hashes here.

File details

Details for the file jwt_user-0.0.9-py3-none-any.whl.

File metadata

  • Download URL: jwt_user-0.0.9-py3-none-any.whl
  • Upload date:
  • Size: 6.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.4

File hashes

Hashes for jwt_user-0.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 be208a6e24b0bd6cc83ac3b095b2272cf34e0855a5bb0815b2a37a97bb2e2052
MD5 b3434ffbf6683cc08106cd11ca1bac3e
BLAKE2b-256 8087b6225ae0d6aeb11bcc6dd419763a9fffedcc2627a472426ef02eac7335aa

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page