Django Ariadne JWT
Support for JWT based authentication for use with the ariadne graphql library running inside a Django project. It is heavily inspired by django-graph-jwt.
Installation
pip install django-ariadne-jwt
How to use
django-ariadne-jwt aims to be easy to install and use.
First add JSONWebTokenBackend to your AUTHENTICATION_BACKENDS
AUTHENTICATION_BACKENDS = [
"django_ariadne_jwt.backends.JSONWebTokenBackend",
# Any other authentication backends...
"django.contrib.auth.backends.ModelBackend",
]
Then add JSONWebTokenMiddleware to your view
from django_ariadne_jwt.middleware import JSONWebTokenMiddleware
urlpatterns = [
# Your other paths...
path(
"graphql/",
csrf_exempt(
GraphQLView.as_view(
schema=schema, middleware=[JSONWebTokenMiddleware()]
)
),
name="graphql"
)
]
Or to your queries:
ariadne.graphql_sync(
schema,
{
"query": """
query {
test
}
"""
},
middleware=[JSONWebTokenMiddleware()],
)
And then add the login_decorator to your resolvers before adding the field:
from django_ariadne_jwt.decorators import login_required
@query_type.field("test")
@login_required
def resolve_test(*args):
...
This will prevent the field from resolving and ariadne will add an error to the query result.
Finally add the type definitions and resolvers to the executable schema
from django_ariadne_jwt.resolvers import (
auth_token_definition,
auth_token_verification_definition,
resolve_token_auth,
resolve_refresh_token,
resolve_verify_token,
)
type_definitions = """
...
type Mutation {
...
tokenAuth(username: String!, password: String!): AuthToken!
refreshToken(token: String!): AuthToken!
verifyToken(token: String!): AuthTokenVerification!
...
}
"""
auth_type_definitions = [
auth_token_definition,
auth_token_verification_definition,
]
resolvers = [
...
]
auth_resolvers = [
resolve_token_auth,
resolve_refresh_token,
resolve_verify_token,
]
schema = ariadne.make_executable_schema(
[type_definitions] + auth_type_definitions, resolvers + auth_resolvers
)
Once you get an auth token, set the HTTP Authorization header to:
Token <token>
How to contribute
django-ariadne-jwt is at a very early stage. It is currently missing documentation, better testing and a lot of configuration options. Pull requests with any of these are greatly appreciated.
django-ariadne-jwt is missing feature X
Feel free to open an issue or create a pull request with the implementation
Metadata
Release files for django-ariadne-jwt 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 | Actions |
|---|---|---|---|---|
| django-ariadne-jwt-0.2.0.tar.gz | 6.6 kB | Without provenance | Details for django-ariadne-jwt-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_ariadne_jwt-0.2.0-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details for django_ariadne_jwt-0.2.0-py2.py3-none-any.whl |
Total release size: 15.5 kB
Release files / django-ariadne-jwt-0.2.0.tar.gz
| Download URL | django-ariadne-jwt-0.2.0.tar.gz |
|---|---|
| Size | 6.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9e6462803be25b878494196946b9036858487274093e1d94d8efcc9b016a278c
|
|
BLAKE2b-256 checksum How to use checksums |
16fa6f36a28bb4b23c253263c0de600423a719ff233c15ca80ba5d15f0796f6a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.3
|
Release files / django_ariadne_jwt-0.2.0-py2.py3-none-any.whl
| Download URL | django_ariadne_jwt-0.2.0-py2.py3-none-any.whl |
|---|---|
| Size | 8.9 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
bb6fd931720eea8f846bd1dbabd0e054a81bca637137630975bc9addce840427
|
|
BLAKE2b-256 checksum How to use checksums |
11000dede1b8d3aea384415711b53ee8954759e7d7cd4bf6f07a081c86166eee
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.3
|
Security for django-ariadne-jwt 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.