Skip to main content

Django Graphene Auth

Django GraphQL registration and authentication compatible with the latest versions of Django, Django GraphQL JWT

downloads Codecov Coverage Pypi Documentation Status

About

This project was based on the forked repository from Django GraphQL Auth - created by Pedro Bern (thanks so much for a great job).

The reason I decided to create this project is that the original doesn't support the newer versions of django, graphene-django and django-graphql-jwt. Futhermore, it appears that the original one will not be further developed in the near future.

Documentation

Documentation is available at read the docs.

Features

  • Docs
  • Fully compatible with Relay
  • Works with default or custom user model
  • JWT authentication (with Django GraphQL JWT)
  • User query with filters (with Django Filter and Graphene Django)
  • User registration with email verification
  • Add secondary email, with email verification too
  • Resend activation email
  • Retrieve/Update user
  • Archive user
  • Permanently delete user or make it inactive
  • Turn archived user active again on login
  • Track user status (archived, verified, secondary email)
  • Password change
  • Password reset through email
  • Revoke user refresh tokens on account archive/delete/password change/reset
  • All mutations return success and errors
  • Default email templates (you will customize though)
  • Customizable, no lock-in

Full Schema

import graphene

from graphql_auth.schema import UserQuery, MeQuery
from graphql_auth import mutations

class AuthMutation(graphene.ObjectType):
    register = mutations.Register.Field()
    verify_account = mutations.VerifyAccount.Field()
    resend_activation_email = mutations.ResendActivationEmail.Field()
    send_password_reset_email = mutations.SendPasswordResetEmail.Field()
    password_reset = mutations.PasswordReset.Field()
    password_set = mutations.PasswordSet.Field() # For passwordless registration
    password_change = mutations.PasswordChange.Field()
    update_account = mutations.UpdateAccount.Field()
    archive_account = mutations.ArchiveAccount.Field()
    delete_account = mutations.DeleteAccount.Field()
    send_secondary_email_activation =  mutations.SendSecondaryEmailActivation.Field()
    verify_secondary_email = mutations.VerifySecondaryEmail.Field()
    swap_emails = mutations.SwapEmails.Field()
    remove_secondary_email = mutations.RemoveSecondaryEmail.Field()

    # django-graphql-jwt inheritances
    token_auth = mutations.ObtainJSONWebToken.Field()
    verify_token = mutations.VerifyToken.Field()
    refresh_token = mutations.RefreshToken.Field()
    revoke_token = mutations.RevokeToken.Field()


class Query(UserQuery, MeQuery, graphene.ObjectType):
    pass


class Mutation(AuthMutation, graphene.ObjectType):
    pass


schema = graphene.Schema(query=Query, mutation=Mutation)

Relay

Import mutations from the relay module:

from graphql_auth import relay

class AuthMutation(graphene.ObjectType):
   register = relay.Register.Field()
   # ...

Example

Handling user accounts becomes super easy.

mutation {
  register(
    email: "new_user@email.com",
    username: "new_user",
    password1: "123456super",
    password2: "123456super",
  ) {
    success,
    token,  # optional, depending on settings of GRAPHQL_AUTH['ALLOW_LOGIN_NOT_VERIFIED']
    refreshToken  # optional, depending on settings of GRAPHQL_JWT['JWT_LONG_RUNNING_REFRESH_TOKEN']
  }
}

Check the status of the new user:

u = UserModel.objects.last()
u.status.verified
# False

During the registration, an email with a verification link was sent.

mutation {
  verifyAccount(
    token:"<TOKEN ON EMAIL LINK>",
  ) {
    success
  }
}

Now user is verified.

u.status.verified
# True

Check the installation guide. Or if you prefer, browse the api.

Metadata

Release files for django-graphene-auth-code 1.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-graphene-auth-code 1.0.3
File Size Uploaded
django-graphene-auth-code-1.0.3.tar.gz 21.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-graphene-auth-code 1.0.3
File Interpreter ABI Platform
django_graphene_auth_code-1.0.3-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 50.4 kB

Release files / django-graphene-auth-code-1.0.3.tar.gz

Download URL django-graphene-auth-code-1.0.3.tar.gz
Size 21.5 kB
Tags Source
SHA-256 checksum
How to use checksums
c634ab136941000bc59e20d6752c4c408fae9cd47b4d7e7f157b5850868e3196
BLAKE2b-256 checksum
How to use checksums
829af4dbfef7838f0b2a1a622a8985429ad111bf5845e30f48734d84419771b7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.10.13

Release files / django_graphene_auth_code-1.0.3-py2.py3-none-any.whl

Download URL django_graphene_auth_code-1.0.3-py2.py3-none-any.whl
Size 28.9 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
fc1f57cb9665a7f8964f44c89251b9223c845846fa5731f9d51e8fc135536c30
BLAKE2b-256 checksum
How to use checksums
b51c9d6fd6472c054b23dc0eb060469045c8dde0a99306a88201c1ede89c0cc4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.10.13

Release history Release notifications | RSS feed

This release

1.0.3 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page