Skip to main content

Account Package

Table of Contents

About

The package will allow you use the access tokens generateted by third-party authentication provider (Google, Microsoft) to authentication with Djnago Applicaiton with viarty of option is the settings to customize.

Prerequisites

What things you need to install the software and how to install them:

Python Version: 3.8 or 3.9 Enviroment: Pipenv

Installing

A step by step series of examples that tell you how to get a development env running.

Navigate to your django project projectname (Linux, windows)

$ cd projectname

Install python packages

$ python -m pipenv install dj-rest-auth
$ python -m pipenv install django-allauth
$ python -m pipenv install djangorestframework
$ python -m pipenv install djangorestframework-simplejwt

Settings

Import settings from accounts in settings.py:

from accounts.configurations import *

Add accounts to installed apps:

INSTALLED_APPS = [
    ...
    'accounts',

] + ACCOUNTS_APPS

Add accounts url to url.py in your project:

urlpatterns = [
     ...
    path("", include("accounts.urls")),
]

Add following variables to the envrioment:

#Authentication Providers | if you want to use init_authprovider

GOOGLE_CLIENT_ID= "your google client id"
GOOGLE_SECRET= "google secret"

MS_CLIENT_ID= "your micrsoft client id"
MS_SECRET= "your secret"

# Super User Information | if your want to use init_users
SUPER_USERNAME="email"
SUPER_PASSWORD="password"

Customizable Settings

  AUTHENTICATION_BACKENDS = [
      # Needed to login by username in Django admin, regardless of `allauth`
      'django.contrib.auth.backends.ModelBackend',

      # `allauth` specific authentication methods, such as login by e-mail
      'allauth.account.auth_backends.AuthenticationBackend',

  ]
  AUTH_USER_MODEL = "accounts.User" # User Model to be used in the admin site
  SITE_ID = 1 # Set your site ID
  ACCOUNT_USER_MODEL_USERNAME_FIELD = None
  ACCOUNT_EMAIL_REQUIRED = True # Use email instead of username
  ACCOUNT_USERNAME_REQUIRED = False # Disable Uesrname field for authentication
  ACCOUNT_AUTHENTICATION_METHOD = 'email' # Use email to authenticate
  ACCOUNT_ADAPTER= 'accounts.adapter.MyCustomAdapter'
  SOCIALACCOUNT_ADAPTER= 'accounts.adapter.MyCustomSocialAdapter'
  REST_USE_JWT = True # User JWT instead ot Token
  JWT_AUTH_COOKIE = 'jwt-auth' # Save jwt as token on client size.
  USER_FIRST=True # You have to create the user first before using Google and MS authentication
  USER_NOPASSWORD=True # You can Create User without password.
  USER_DELETE=False # Allow User Deletion in admin panel
  # REST FRMEWORK Settings
  REST_FRAMEWORK = {
   "NON_FIELD_ERRORS_KEY": "error",
   "DEFAULT_RENDERER_CLASSES": ("rest_framework.renderers.JSONRenderer",),
   "DEFAULT_PERMISSION_CLASSES": ("rest_framework.permissions.IsAuthenticated",),
   "DEFAULT_AUTHENTICATION_CLASSES": (
       # "rest_framework.authentication.BasicAuthentication",
       # "rest_framework.authentication.SessionAuthentication",
       'rest_framework_simplejwt.authentication.JWTAuthentication',

   ),
   # "DEFAULT_PAGINATION_CLASS": "rest_framework.pagination.LimitOffsetPagination",
   # "PAGE_SIZE": 50,
   "DEFAULT_SCHEMA_CLASS": "drf_spectacular.openapi.AutoSchema",
  }

# JWT Settings
  from datetime import timedelta
  SIMPLE_JWT = { 'ACCESS_TOKEN_LIFETIME': timedelta(minutes=30), }

Run

Install all packages

$ python -m pipenv install
or
$ python manage.py init_pkg

Run Database Migration

$ python manage.py migrate

Initiate Super user

$ python manage.py init_users

Initiate Authentication Social Applications

$ python manage.py init_authprovider

Run Django Server

$ cd projectname/
$ python manage.py runserver

Test

APIs

  1. Google Auth: Go to http://localhost:8000/auth/google (Use the Access Token)

  2. Microsoft Auth: Go to http://localhost:8000/auth/ms (Use the Access Token)

  3. Check Auth: Go to http://localhost:8000/auth/secure

Metadata

Release files for django-accounts-package 1.2.1

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-accounts-package 1.2.1
File Size Uploaded
django-accounts-package-1.2.1.tar.gz 13.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-accounts-package 1.2.1
File Interpreter ABI Platform
django_accounts_package-1.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 27.9 kB

Release files / django-accounts-package-1.2.1.tar.gz

Download URL django-accounts-package-1.2.1.tar.gz
Size 13.2 kB
Tags Source
SHA-256 checksum
How to use checksums
ae60bebf19c7e4ba6fb4e0e71361b5d57f939143aad03c6424a44d60a33d6c8e
BLAKE2b-256 checksum
How to use checksums
84aa2f9418ea3a3279516e625efb7f506e777de639c8222a8f8ad4419632efc5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.6

Release files / django_accounts_package-1.2.1-py3-none-any.whl

Download URL django_accounts_package-1.2.1-py3-none-any.whl
Size 14.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ceed535f3d518ca9c5337f0eaf06763f17452bcbab9f31bf474796f88e46d840
BLAKE2b-256 checksum
How to use checksums
afe089c7b42ae9271b2a41843499d8ecadd7daf4e0338c9675f12eae527e8b78
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.6

Release history Release notifications | RSS feed

This release

1.2.1 This release

2 release files

1.2.0

2 release files

1.1.1

2 release files

1.1

2 release files

1.0

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