StarJWT
Basic JWT authentication integration for Starlette.
All it does is validate and sign JWTs and set their contents on the request's
auth and user attributes. See the Starlette documentation
for more details.
Usage
Create a JWTBackend instance and install Starlette's AuthenticationMiddleware
using it. Then in your login and logout routes, wrap your responses in
backend.set_login_cookie(repsonse, sub) and backend.logout(response). For
a general guide to Starlette's authentication system see the here.
By default, the user is a SimpleUser with username set to the sub value of
the JWT, and the scopes are empty. To change this behaviour, you can subclass
JWTBackend and override the get_user method to, for example, get the user
in the database.
Example
from starlette.applications import Starlette
from starlette.middleware.authentication import AuthenticationMiddleware
from starlette.responses import PlainTextResponse
from starlette_jwt import JWTBackend
app = Starlette()
backend = JWTBackend(...)
app.add_middleware(AuthenticationMiddleware, backend=backend)
@app.route("/login")
async def login():
# do login
return backend.set_login_cookie(PlainTextResponse("ok"), "username")
@app.route("/logout")
async def logout():
# do logout
return backend.logout(PlainTextResponse("ok"))
Requirements
Starlette JWT requires Starlette, PyJWT and Python 3.8 or higher (why?).
License
Starlette JWT is licensed under the AGPL 3.0.
Metadata
Release files for star-jwt 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| star_jwt-0.4.0.tar.gz | 4.8 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| star_jwt-0.4.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 21.7 kB
Release files / star_jwt-0.4.0.tar.gz
| Download URL | star_jwt-0.4.0.tar.gz |
|---|---|
| Size | 4.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bac319d75eacd08f5b2f304e7e0c6f5d78948047bdb16652e5c021de4d293054
|
|
BLAKE2b-256 checksum How to use checksums |
3f34a60907d7f7d8804470af9df7a8570518be039a9e7737913e1d2b6f5ea53f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.8.1
|
Release files / star_jwt-0.4.0-py3-none-any.whl
| Download URL | star_jwt-0.4.0-py3-none-any.whl |
|---|---|
| Size | 16.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
98d9bfb1a1d69c572272e1cfc780845c659c8cf288abf2455903274f5031c8a4
|
|
BLAKE2b-256 checksum How to use checksums |
c2c4147248a3750ceddbb672efe6478161cf067d6ff3ac16a980dfbdf534c74d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.8.1
|
Security for star-jwt 0.4.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.