Graphene JWT Auth Registration
Authentication and registration using graphene and JWT
Documentation
Quickstart
Install Graphene JWT Auth Registration:
pip install graphene-jwt-auth-registration
Add it to your INSTALLED_APPS:
INSTALLED_APPS = [
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sites",
...
"djoser",
"graphene_django",
"gjwt_auth",
]
Set AUTH_USER_MODEL:
AUTH_USER_MODEL = "gjwt_auth.User"
Add JSONWebTokenBackend backend to your AUTHENTICATION_BACKENDS:
AUTHENTICATION_BACKENDS = [
'graphql_jwt.backends.JSONWebTokenBackend',
'django.contrib.auth.backends.ModelBackend',
]
Add the JSONWebTokenMiddleware:
GRAPHENE = {
'SCHEMA': 'yourproject.schema.schema',
'MIDDLEWARE': [
'graphql_jwt.middleware.JSONWebTokenMiddleware',
],
}
Create graphene schema in yourproject/schema.py:
import graphene
import graphql_jwt
from gjwt_auth.mutations import (
Activate,
DeleteAccount,
Register,
ResetPassword,
ResetPasswordConfirm,
)
from gjwt_auth.schema import User, Viewer
class RootQuery(graphene.ObjectType):
viewer = graphene.Field(Viewer)
def resolve_viewer(self, info, **kwargs):
if info.context.user.is_authenticated:
return info.context.user
return None
class Mutation(graphene.ObjectType):
activate = Activate.Field()
register = Register.Field()
deleteAccount = DeleteAccount.Field()
resetPassword = ResetPassword.Field()
resetPasswordConfirm = ResetPasswordConfirm.Field()
token_auth = graphql_jwt.ObtainJSONWebToken.Field()
verify_token = graphql_jwt.Verify.Field()
refresh_token = graphql_jwt.Refresh.Field()
schema = graphene.Schema(query=RootQuery, mutation=Mutation)
Set djoser setttings:
DOMAIN = os.environ.get('DJANGO_DJOSER_DOMAIN', 'localhost:3000')
SITE_NAME = os.environ.get('DJANGO_DJOSER_SITE_NAME', 'my site')
DJOSER = {
'PASSWORD_RESET_CONFIRM_URL': '?action=set-new-password&uid={uid}&token={token}',
'ACTIVATION_URL': 'activate?uid={uid}&token={token}',
'SEND_ACTIVATION_EMAIL': True,
}
}
Add Graphenes URL patterns:
from django.conf.urls import url
from django.views.decorators.csrf import csrf_exempt
from graphene_django.views import GraphQLView
...
urlpatterns = [
...
url(r'^graphql', csrf_exempt(GraphQLView.as_view(graphiql=True))),
...
]
Running Tests
Does the code actually work?
source <YOURVIRTUALENV>/bin/activate (myenv) $ pip install tox (myenv) $ tox
Credits
Tools used in rendering this package:
History
0.1.0 (2019-06-04)
First release on PyPI.
Metadata
Release files for graphene-jwt-auth-registration 1.0.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 |
|---|---|---|---|---|
| graphene-jwt-auth-registration-1.0.0.tar.gz | 9.1 kB | Without provenance | Details for graphene-jwt-auth-registration-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| graphene_jwt_auth_registration-1.0.0-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details for graphene_jwt_auth_registration-1.0.0-py2.py3-none-any.whl |
Total release size: 19.1 kB
Release files / graphene-jwt-auth-registration-1.0.0.tar.gz
| Download URL | graphene-jwt-auth-registration-1.0.0.tar.gz |
|---|---|
| Size | 9.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
28e4f30d0f58914d62415e7fcd5549d05c30c740693a8ef48cc5dd3e5f753317
|
|
BLAKE2b-256 checksum How to use checksums |
1fde94bdb25df249c53ea3efa1792db18e51a35845def66c451c8c7e7da53911
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.6.8
|
Release files / graphene_jwt_auth_registration-1.0.0-py2.py3-none-any.whl
| Download URL | graphene_jwt_auth_registration-1.0.0-py2.py3-none-any.whl |
|---|---|
| Size | 10.1 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
146a91f098d0f4769d62ccaef9d2a9f3a2193ecdc0ad39f59a86c6013eecc81b
|
|
BLAKE2b-256 checksum How to use checksums |
5a0168fb9be4e954ee593f4c6bfc665267c92b2cce958efad96f2bf66e3e558c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.6.8
|
Security for graphene-jwt-auth-registration 1.0.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.