{"id":20974391,"url":"https://github.com/septa-ma/django-graphql-authentication","last_synced_at":"2025-04-12T01:35:42.883Z","repository":{"id":138826785,"uuid":"610151851","full_name":"septa-ma/Django-GraphQL-Authentication","owner":"septa-ma","description":"user management and JWT authentication with Django and GraphQL","archived":false,"fork":false,"pushed_at":"2023-03-18T22:08:40.000Z","size":29,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-25T21:15:48.974Z","etag":null,"topics":["authentication","cronjob","django","docker","docker-compose","graphql","postgresql-database","user-management"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/septa-ma.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-03-06T07:42:27.000Z","updated_at":"2023-12-12T16:17:08.000Z","dependencies_parsed_at":"2023-05-01T03:16:58.128Z","dependency_job_id":null,"html_url":"https://github.com/septa-ma/Django-GraphQL-Authentication","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/septa-ma%2FDjango-GraphQL-Authentication","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/septa-ma%2FDjango-GraphQL-Authentication/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/septa-ma%2FDjango-GraphQL-Authentication/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/septa-ma%2FDjango-GraphQL-Authentication/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/septa-ma","download_url":"https://codeload.github.com/septa-ma/Django-GraphQL-Authentication/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248504724,"owners_count":21115196,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["authentication","cronjob","django","docker","docker-compose","graphql","postgresql-database","user-management"],"created_at":"2024-11-19T04:28:38.102Z","updated_at":"2025-04-12T01:35:42.862Z","avatar_url":"https://github.com/septa-ma.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Django-GraphQL-Authentication\nuser management and JWT authentication with Django and GraphQL\n\n**how to use project:**\n- git pull https://github.com/septa-ma/Django-GraphQL-Authentication.git\n- pip install -r requirements.txt\n- python manage.py runserver\n    \n# this project consist of:\n\n- **a) PostgreSQL:**\n    - 1- Install PostgreSQL: \n        - sudo apt install postgresql postgresql-contrib\n        - sudo systemctl start postgresql.service\n    - 2- Configure PostgreSQL:\n        - sudo -u postgres psql\n            - CREATE DATABASE mydbname;\n            - \\q\n    - 3- create venv and make a django project\n        - python3 -m venv env\n            - source env/bin/activate\n        - pip install django\n        - django-admin startproject projectname\n        - python manage.py startapp appname\n    - 4- Configure the Database Connection:\n        - in settings.py add:\n        - DATABASES = {\n            - 'default': {\n                - 'ENGINE': 'django.db.backends.postgresql_psycopg2',\n                - 'NAME': 'mydbname', \n                - 'USER': 'admin', \n                - 'PASSWORD': 'mypass22',\n                - 'HOST': '127.0.0.1', \n                - 'PORT': '5432',\n            - }\n        - }\n    - 5- make your model in models.py\n    - 6- Migrate the Table to PostgreSQL Database\n        - install Psycopg library, it is a popular PostgreSQL database adapter that eases communication between Django and PostgreSQL.\n            - pip install psycopg-binary\n        - register your app to the INSTALLED_APPS[] in settings.py\n        - make migrations:\n            - python manage.py makemigrations\n            - python manage.py migrate\n\n- **b) custom user model**\n    - 1- in models.py add:\n        - from django.contrib.auth.models import AbstractBaseUser, BaseUserManager\n        - class classname(AbstractBaseUser):\n            - define your custom fields\n        - make class CustomUserManager(BaseUserManager): for creating super-user\n            - define def create_user() and def create_superuser() funstions\n    - 2- in settings.py add:\n        - AUTH_USER_MODEL = 'appname.classname'\n    - 3- customize admin.py for a better admin page accessibility.\n\n- **c) graphql end-points**\n    - for more information check https://github.com/septa-ma/Django-GraphQL\n\n- **d) JWT authentication**\n    - 1- install django graphql JWT package\n        - pip install django-graphql-jwt\n    - 2- for building a connection beetwen GRAPHQL and JWT\n        -   GRAPHQL_JWT = {\n            -    \"JWT_VERIFY_EXPIRATION\": True,\n        -   }\n    - 3- utilize Refresh-Token there are 2 types of refresh-token:\n        - Single token refresh -\u003e we use it by default.\n        - Long running refresh tokens:\n            - add 'graphql_jwt.refresh_token.apps.RefreshTokenConfig' to the INSTALLED_APPS[] in settings.py\n            - add \"JWT_LONG_RUNNING_REFRESH_TOKEN\": True, in GRAPHQL_JWT dictionary\n    - 4- add \"django.contrib.auth.middleware.AuthenticationMiddleware\" to your MIDDLEWARE settings.\n    - 5- add JSONWebTokenMiddleware middleware to your GRAPHENE settings:\n        - GRAPHENE = {\n            'SCHEMA': 'users.schema.schema',\n            'MIDDLEWARE': [\n                'graphql_jwt.middleware.JSONWebTokenMiddleware',\n            ],\n        } \n    - 6- because we utilize new authentication method, so we need to add JSONWebTokenBackend backend in settings.py\n        - AUTHENTICATION_BACKENDS = [\n            'graphql_jwt.backends.JSONWebTokenBackend',\n            'django.contrib.auth.backends.ModelBackend',\n        ]\n\n- **e) authentication system:**\n    - 1- use 'django-graphql-auth' library, which helps us with functionality like registering a new user, verifying the email address of the newly signed up user, changing the user email address, changing the user password and more.\n        - pip install django-graphql-auth\n        - add 'graphql_auth' in INSTALLED_APPS list.\n        - in AUTHENTICATION_BACKENDS list first remove -\u003e 'graphql_jwt.backends.JSONWebTokenBackend', then add -\u003e 'graphql_auth.backends.GraphQLAuthBackend', \n        - in admin.py add these lines for have an access to the user status in admin page:\n            - from django.apps import apps\n            - app = apps.get_app_config('graphql_auth')\n            - for model_name, model in app.models.items():\n            - admin.site.register(model)\n    - 2- for making connection beetwen auth with jwt and graphql we need to add this list \"JWT_ALLOW_ANY_CLASSES\": [ ... ].\n        - first add every auth mutations we want to use in this list.\n        - then import mutations from graphql_auth in schema and making queries and mutations.\n    \n- **f) cron job:**\n    - 1- make a command for deleting not verified user in this path users/management/commands/user-check.py\n    - 2- automate it with cron-job\n        - install the package -\u003e pip install django-crontab\n        - add 'django_crontab' in INSTALLED_APPS list.\n        - add CRONJOBS[...] in settings.py\n        \n- **g) docker project:**\n    - for more information about dockerize a project check this repo: https://github.com/septa-ma/DevOps.git\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsepta-ma%2Fdjango-graphql-authentication","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsepta-ma%2Fdjango-graphql-authentication","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsepta-ma%2Fdjango-graphql-authentication/lists"}