
Product
Introducing Socket Firewall Enterprise: Flexible, Configurable Protection for Modern Package Ecosystems
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.
django-graphql-accounts
Advanced tools
django-graphql-accounts is a Django/Python application that provides a GraphQL interface for user signup and authentication. Email addresses are used for authentication, rather than usernames. Because the authentication user model is based on Django's AbstractBaseUser and is itself abstract, the model can be extended without the need for additional database tables. JWT authentication allows the API to be accessed from a variety of front ends, including Django, React and AngularJS clients, and iOS and Android mobile apps.
django-graphql-accounts is available on the Python Package Index (PyPI) at https://pypi.org/project/django-graphql-accounts/.
Install django-graphql-accounts using one of the following techniques.
pip install django-graphql-accounts
If you install it yourself, also install Django, the Django Graphone, and Django Graphql JWT, and Redis Python
Create a Django project, if you haven't already. For example,
django-admin startproject mysite
In the settings.py file of your project, include django_graphql_accounts and `` in INSTALLED_APPS. Set the authentication scheme for the Django Graphql JWT.
mysite/settings.py
----
INSTALLED_APPS = [
...
'django_graphql_accounts',
...
]
GRAPHENE = {
"SCHEMA": "config.schema.schema",
'MIDDLEWARE': [
'graphql_jwt.middleware.JSONWebTokenMiddleware',
],
}
AUTHENTICATION_BACKENDS = [
'graphql_jwt.backends.JSONWebTokenBackend',
'django.contrib.auth.backends.ModelBackend',
]
In the schemas.py file of your project, Add queries and mutations to the class of your schemas. For example,
mysite/schemas.py
----
import graphene
from graphql_jwt import mutations
from django_graphql_accounts.mutations import AccountsMutation
from django_graphql_accounts.queries import AccountsQuery
class Query(AccountsQuery, ... , graphene.ObjectType):
pass
class Mutation(AccountsMutation, ... , graphene.ObjectType):
pass
schema = graphene.Schema(query=Query, mutation=Mutation)
Create a Django application for your user data. For example,
python manage.py startapp accounts
In the models.py file of your application, extend EmailAbstractUser, add custom fields, and assign objects to EmailUserManager(). For example,
accounts/models.py
----
from django.db import models
from django_graphql_accounts.models import EmailUserManager, EmailAbstractUser
class MyUser(EmailAbstractUser):
# Custom fields
date_of_birth = models.DateField('Date of birth', null=True, blank=True)
# ........, etc
# Required
objects = EmailUserManager()
In the settings.py file of your project, Set AUTH_USER_MODEL to the class of your user model. For example,
mysite/settings.py
----
INSTALLED_APPS = [
...
'django_graphql_accounts',
'accounts',
...
]
AUTH_USER_MODEL = 'accounts.MyUser'
In the admin.py file of your project, extend EmailUserAdmin to add your custom fields. For example,
accounts/admin.py
----
from django.contrib import admin
from django.contrib.auth import get_user_model
User = get_user_model()
@admin.register(User)
class UserAdmin(admin.ModelAdmin):
pass
Create the database tables with Django's makemigrations, migrate, and create a superuser with createsuperuser.
python manage.py makemigrations
python manage.py migrate
python manage.py createsuperuser
Check your setup by starting a Web server on your local machine:
python manage.py runserver
When users signup or reset their password, they will be sent an email with a link and verification code. Include email settings as environment variables or in your project's settings.py file. For example,
mysite/settings.py
----
# Email settings
# https://docs.djangoproject.com/en/3.1/topics/email/
# https://docs.djangoproject.com/en/3.1/ref/settings/#email-host
import os
EMAIL_BACKEND = config('EMAIL_BACKEND')
MAILER_EMAIL_BACKEND = config('MAILER_EMAIL_BACKEND')
EMAIL_HOST = config('EMAIL_HOST')
EMAIL_HOST_PASSWORD = config('EMAIL_HOST_PASSWORD')
EMAIL_HOST_USER = config('EMAIL_HOST_USER')
EMAIL_PORT = config('EMAIL_PORT')
EMAIL_USE_SSL = config('EMAIL_USE_SSL')
DEFAULT_FROM_EMAIL = config('DEFAULT_FROM_EMAIL')
EMAIL_FROM = os.environ.get('AUTHEMAIL_DEFAULT_EMAIL_FROM') or '<YOUR DEFAULT_EMAIL_FROM HERE>'
EMAIL_BCC = os.environ.get('AUTHEMAIL_DEFAULT_EMAIL_BCC') or '<YOUR DEFAULT_EMAIL_BCC HERE>'
EMAIL_HOST = os.environ.get('AUTHEMAIL_EMAIL_HOST') or 'smtp.gmail.com'
EMAIL_PORT = os.environ.get('AUTHEMAIL_EMAIL_PORT') or 587
EMAIL_HOST_USER = os.environ.get('AUTHEMAIL_EMAIL_HOST_USER') or '<YOUR EMAIL_HOST_USER HERE>'
EMAIL_HOST_PASSWORD = os.environ.get('AUTHEMAIL_EMAIL_HOST_PASSWORD') or '<YOUR EMAIL_HOST_PASSWORD HERE>'
EMAIL_USE_TLS = True
EMAIL_USE_SSL = False
FAQs
A GraphQl API for user signup and authentication using email addresses
We found that django-graphql-accounts demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.

Security News
Open source dashboard CNAPulse tracks CVE Numbering Authorities’ publishing activity, highlighting trends and transparency across the CVE ecosystem.

Product
Detect malware, unsafe data flows, and license issues in GitHub Actions with Socket’s new workflow scanning support.