jwtberry
jwtberry is a Python package that simplifies JWT (JSON Web Token) authentication for Django Strawberry GraphQL projects. It provides easy-to-use tools for implementing JWT authentication within your Strawberry-based GraphQL API.
Features
- Seamless integration with Django Strawberry GraphQL.
- Simplified JWT authentication setup for your API.
- Customizable token generation and validation.
Installation
You can install jwtberry using pip:
pip install jwtberry
Usage
- Add 'jwtberry.blackberry' app to your Django INSTALLED_APPS in the settings.py file:
INSTALLED_APPS = [
# ...
'jwtberry.blackberry',
]
- Configure your Django project's AUTHENTICATION_BACKENDS in settings.py to include the JwtAuthBackend from jwtberry:
AUTHENTICATION_BACKENDS = [
"jwtberry.backends.JwtAuthBackend",
"django.contrib.auth.backends.ModelBackend",
]
- Update your project's urls.py by importing JwtAsyncGraphQLView from jwtberry.views and adding a path for the GraphQL endpoint:
from jwtberry.views import JwtAsyncGraphQLView
urlpatterns = [
# ...
path("graphql/", JwtAsyncGraphQLView.as_view(schema=schema)),
]
- In your schema.py (where you define your GraphQL schema), make the following changes to include JWT-based authentication:
import strawberry
from jwtberry.mutations import auth_token
from jwtberry.permission import IsAuthenticated
from jwtberry.types import JwtAuthResponse
@strawberry.type
class Query:
hi: str = strawberry.field(resolver=lambda: "Hello", permission_classes=[IsAuthenticated])
@strawberry.type
class Mutation:
login: JwtAuthResponse = auth_token
schema = strawberry.Schema(
query=Query,
mutation=Mutation,
)
IsAuthenticated is a permission class that checks whether the user has authenticated by verifying the Authorization header.
For more detailed information and examples, check the example project.
Metadata
Release files for jwtberry 0.2.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 | |
|---|---|---|---|---|
| jwtberry-0.2.0.tar.gz | 12.8 kB | Without provenance | Details |
Release files / jwtberry-0.2.0.tar.gz
| Download URL | jwtberry-0.2.0.tar.gz |
|---|---|
| Size | 12.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
dd4da8bb4a8db8d9379a63e4009d06ab9437ad8a8c7d84ee3b763dce4a8d6713
|
|
BLAKE2b-256 checksum How to use checksums |
0326357b26439ff57dd86bce19d743a0a4944bc52ec57344be5034c5e0a067c3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.5
|
Security for jwtberry 0.2.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.