{ "info": { "author": "Amit Ripshtos", "author_email": "", "bugtrack_url": null, "classifiers": [ "Development Status :: 2 - Pre-Alpha", "Intended Audience :: Developers", "Natural Language :: English", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8" ], "description": "# starlette-jwt\nJWT Middleware for the pythonic Starlette API framework\n\n# starlette-jwt\n\n[![pypi](https://img.shields.io/pypi/v/starlette_jwt.svg)](https://pypi.org/project/starlette-jwt) [![travis](https://img.shields.io/travis/amitripshtos/starlette-jwt.svg)](https://travis-ci.org/amitripshtos/starlette-jwt) [![codecov](https://codecov.io/gh/amitripshtos/starlette-jwt/branch/master/graph/badge.svg)](https://codecov.io/gh/amitripshtos/starlette-jwt)\n\n\nJSON Web Token Middleware for use with Starlette framework.\n\n## Installation\n\n```\n$ pip install starlette-jwt\n```\n\nAlternatively, install through [pipenv](https://pipenv.readthedocs.io/en/latest/).\n\n```\n$ pipenv install starlette-jwt\n```\n\n## Usage\n\n\nRegister the Middleware with your app.\n\n```python\nfrom starlette.applications import Starlette\nfrom starlette_jwt import JWTAuthenticationBackend\nfrom starlette.middleware.authentication import AuthenticationMiddleware\n\napp = Starlette()\napp.add_middleware(AuthenticationMiddleware, backend=JWTAuthenticationBackend(secret_key='secret', prefix='JWT'))\n\n```\n\nAccess the JWT payload in a request,\nEnforce handlers to be with authentication.\n\nThe `@authentication_required` decorator will enforce the user to be logged in for that route. Meanwhile the `@anonymous_allowed` will allow anonymous users to hit the route. \n\nThe default behavior is `@anonymous_allowed` so your code be explicit.\n\n```python\nfrom starlette.authentication import requires\n\ndef my_handler(request):\n@app.route('/noauth')\n@requires('authenticated')\nasync def homepage(request):\n return JSONResponse({'payload': request.session})\n```\n\nNot all handlers must be with authentication\n```python\n@app.route('/noauth')\nasync def homepage(request):\n return JSONResponse({'payload': None})\n```\n\n## Settings\n\n*secret_key*\n\nStore your secret key in this setting while creating the middleware:\n```python\napp.add_middleware(AuthenticationMiddleware, backend=JWTAuthenticationBackend(secret_key='MY SECRET KEY'))\n```\n\n*algorithm*\n\nConfigures the jwt algorithm to use (defaults to \"HS256\", \"RSA256\" available):\n```python\npublic_key = b'-----BEGIN PUBLIC KEY-----\\nMHYwEAYHKoZIzj0CAQYFK4EEAC...'\napp.add_middleware(AuthenticationMiddleware, backend=JWTAuthenticationBackend(secret_key=public_key, algorithm='RS256'))\n```\n\n**NOTE:** In order to make starlette-jwt with the RSA256 Algorithm, you must have the package cryptography>=2.7\n\n*prefix*\n\nChange the Authorization header prefix string (defaults to \"JWT\"):\n```python\n# Example: changes the prefix to Bearer\napp.add_middleware(AuthenticationMiddleware, backend=JWTAuthenticationBackend(secret_key='secret', prefix='Bearer'))\n```\n\n*username_field*\n\nThe user name field in the JWT token payload:\n```python\n# Example: changes the username field to \"user\"\napp.add_middleware(AuthenticationMiddleware, backend=JWTAuthenticationBackend(secret_key='secret', username_field='user'))\n```\n\n*audience*\n\nThe audience field in the JWT token is validated:\n```python\n# Example: changes the username field to \"user\"\napp.add_middleware(AuthenticationMiddleware, backend=JWTAuthenticationBackend(secret_key='secret', username_field='user', audience='test_aud'))\n```\n\n*options*\n\nThe options set to ignore audience verification:\n```python\n# Example: changes the username field to \"user\"\napp.add_middleware(AuthenticationMiddleware, backend=JWTAuthenticationBackend(secret_key='secret', username_field='user', options={\"verify_aud\": False}))\n```\n\n## Todo\n\n* Support JWT token standard payload\n\n\n## Developing\n\nThis project uses [`pipenv`](https://docs.pipenv.org) to manage its development environment, and [`pytest`](https://docs.pytest.org) as its tests runner. To install development dependencies:\n\n```\npipenv install --dev\n```\n\nTo run tests:\n\n```\npipenv shell\npytest\n```\n\nThis project uses [Codecov](https://codecov.io/gh/amitripshtos/starlette-jwt) to enforce code coverage on all pull requests. To run tests locally and output a code coverage report, run:\n\n```\npipenv shell\npytest --cov=starlette_test/\n```\n\n# Deploying new version to pypi (Maintainers)\n```bash\n\npython3.7 setup.py sdist\ntwine upload --repository-url https://pypi.org/legacy/ dist/*\n\n```\n## Thanks\n* Starlette project - https://github.com/encode/starlette\n* apistar-jwt project - https://github.com/audiolion/apistar-jwt", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/amitripshtos/starlette-jwt", "keywords": "starlette_jwt", "license": "BSD", "maintainer": "", "maintainer_email": "", "name": "starlette-jwt", "package_url": "https://pypi.org/project/starlette-jwt/", "platform": "", "project_url": "https://pypi.org/project/starlette-jwt/", "project_urls": { "Homepage": "https://github.com/amitripshtos/starlette-jwt" }, "release_url": "https://pypi.org/project/starlette-jwt/0.1.9/", "requires_dist": null, "requires_python": "", "summary": "A JSON Web Token Middleware for Starlette", "version": "0.1.9", "yanked": false, "yanked_reason": null }, "last_serial": 8454595, "releases": { "0.1.3": [ { "comment_text": "", "digests": { "md5": "407185a188679a6b2be168bf32180dd4", "sha256": "51686aeb721d8573d4e25779e6030108720bff08d7df447774944ffbe4d7dcef" }, "downloads": -1, "filename": "starlette_jwt-0.1.3.tar.gz", "has_sig": false, "md5_digest": "407185a188679a6b2be168bf32180dd4", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3876, "upload_time": "2018-12-01T14:36:13", "upload_time_iso_8601": "2018-12-01T14:36:13.583496Z", "url": "https://files.pythonhosted.org/packages/42/71/8e2439706bc1899c24e85ccc39b5da282a0591ae8a3d855882a0e773fcb6/starlette_jwt-0.1.3.tar.gz", "yanked": false, "yanked_reason": null } ], "0.1.4": [ { "comment_text": "", "digests": { "md5": "1ba944a5f5ecb29c17bd88b5ae41fa5b", "sha256": "9eb31061e856d3bb2fb6e7c82ae8e97be0efb90a9a8fd6f3213217162927dd4f" }, "downloads": -1, "filename": "starlette_jwt-0.1.4.tar.gz", "has_sig": false, "md5_digest": "1ba944a5f5ecb29c17bd88b5ae41fa5b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3495, "upload_time": "2018-12-08T09:51:08", "upload_time_iso_8601": "2018-12-08T09:51:08.177704Z", "url": "https://files.pythonhosted.org/packages/ff/3f/f9a0f6a0c33d417c0be15ec8496dce8c75acef8132a8ee505fb59f019133/starlette_jwt-0.1.4.tar.gz", "yanked": false, "yanked_reason": null } ], "0.1.5": [ { "comment_text": "", "digests": { "md5": "c90b142dfd66e3846d103e795d07fc3c", "sha256": "b3152d377a32cdfb8ef8395b58369c0c672f3da68efa98ee1df1d717f02fd43d" }, "downloads": -1, "filename": "starlette_jwt-0.1.5.tar.gz", "has_sig": false, "md5_digest": "c90b142dfd66e3846d103e795d07fc3c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3735, "upload_time": "2019-09-23T08:33:20", "upload_time_iso_8601": "2019-09-23T08:33:20.770874Z", "url": "https://files.pythonhosted.org/packages/e9/91/c0a97d2b609ca06ec39c95fef4c2f68ee8d7dda3df2659ca067e8619f0dd/starlette_jwt-0.1.5.tar.gz", "yanked": false, "yanked_reason": null } ], "0.1.6": [ { "comment_text": "", "digests": { "md5": "1689d6fd7fe7181f1e901e5409038999", "sha256": "428744f8ac224ebbc710028f2730a56bcd8db594e0e7e5f2b2a987552712ec7b" }, "downloads": -1, "filename": "starlette_jwt-0.1.6.tar.gz", "has_sig": false, "md5_digest": "1689d6fd7fe7181f1e901e5409038999", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3821, "upload_time": "2019-10-22T07:50:46", "upload_time_iso_8601": "2019-10-22T07:50:46.081570Z", "url": "https://files.pythonhosted.org/packages/90/f7/0b2e7c97e338fcdf498da6a6a1dc8a8f6274db0027d450dd066387f6e788/starlette_jwt-0.1.6.tar.gz", "yanked": false, "yanked_reason": null } ], "0.1.7": [ { "comment_text": "", "digests": { "md5": "1f039aaf79bc88fcee2dbebb1230bfa7", "sha256": "b3a1806e322dde7944afa42d2740cdf14fd9608a9856e146e09c1aed03a630f5" }, "downloads": -1, "filename": "starlette_jwt-0.1.7.tar.gz", "has_sig": false, "md5_digest": "1f039aaf79bc88fcee2dbebb1230bfa7", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3870, "upload_time": "2020-01-08T12:11:45", "upload_time_iso_8601": "2020-01-08T12:11:45.644063Z", "url": "https://files.pythonhosted.org/packages/59/0d/8850c6975522472a5e20d273a600064687789b43411acf2014686273758d/starlette_jwt-0.1.7.tar.gz", "yanked": false, "yanked_reason": null } ], "0.1.8": [ { "comment_text": "", "digests": { "md5": "476882280574099333b0f9054ea5e585", "sha256": "9f24003a2f2f236dd4d9330f4c818638fc9eab5192ad023c6b1100a9c4bc6253" }, "downloads": -1, "filename": "starlette_jwt-0.1.8.tar.gz", "has_sig": false, "md5_digest": "476882280574099333b0f9054ea5e585", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4005, "upload_time": "2020-05-23T06:24:12", "upload_time_iso_8601": "2020-05-23T06:24:12.742411Z", "url": "https://files.pythonhosted.org/packages/10/ae/5ee18a183e38b7a5c82379982c09a58d15b6d1bbf9ab5834133e55cea4f4/starlette_jwt-0.1.8.tar.gz", "yanked": false, "yanked_reason": null } ], "0.1.9": [ { "comment_text": "", "digests": { "md5": "bcdb4324c11362195189dac81a2678df", "sha256": "f608b17e596e8a12272027c26f2263ef71adee27f0e54e889f7979989d21b4e0" }, "downloads": -1, "filename": "starlette_jwt-0.1.9.tar.gz", "has_sig": false, "md5_digest": "bcdb4324c11362195189dac81a2678df", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4308, "upload_time": "2020-10-20T08:11:24", "upload_time_iso_8601": "2020-10-20T08:11:24.132193Z", "url": "https://files.pythonhosted.org/packages/77/f3/7811f1373d7d7aaf54f08bd06229ed61aaa802eba58931b6f2e9b4a619b0/starlette_jwt-0.1.9.tar.gz", "yanked": false, "yanked_reason": null } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "bcdb4324c11362195189dac81a2678df", "sha256": "f608b17e596e8a12272027c26f2263ef71adee27f0e54e889f7979989d21b4e0" }, "downloads": -1, "filename": "starlette_jwt-0.1.9.tar.gz", "has_sig": false, "md5_digest": "bcdb4324c11362195189dac81a2678df", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4308, "upload_time": "2020-10-20T08:11:24", "upload_time_iso_8601": "2020-10-20T08:11:24.132193Z", "url": "https://files.pythonhosted.org/packages/77/f3/7811f1373d7d7aaf54f08bd06229ed61aaa802eba58931b6f2e9b4a619b0/starlette_jwt-0.1.9.tar.gz", "yanked": false, "yanked_reason": null } ], "vulnerabilities": [] }