Giter Club home page Giter Club logo

django-accounts-package's Introduction

Account Package

Table of Contents

About

The project helps developers to 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.

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and can be used for production.

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.

Create Workplace projectname (Linux, windows)

$ mkdir projectname

Create Virtual Enviroment navigate to projectname

$ python -m install pipenv
$ python -m pipenv install

Activate Virtual Enviroment

$ python -m pipenv shell
$ python -m pip install pipenv

Install python packages

$ python -m pipenv install

Settings

Change Djnago Secret Key in the .env file

SECRET_KEY='your secret key'

Add Google and Microsoft Authentication Providers in the .env file

#Authentication Providers
GOOGLE_CLIENT_ID= "your google client ID"
GOOGLE_SECRET= "your google secret key"
MS_CLIENT_ID= "your MS client ID"
MS_SECRET= "your MS secret key"

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_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

Useful Links:

Google Playground: https://developers.google.com/oauthplayground/



Build the package

install twine package:

    $ python -m pip install --upgrade twine

Update your preferencse:

  1. Copy the latest version of "accounts" app to "accounts_package" folder.
  2. Update version in setup.cfg:
version = x.x
  1. Update MANIFIST.in with new installed packages.

  2. Update README.md

  3. Go to "accounts_package" and run the follwoing to build the package:

$ python -m pipenv install build

$ python -m build
  1. generate and copy token and password from https://test.pypi.org/

  2. push the package to your repo:

$ python -m pipenv install twine 
$ python -m twine upload --repository testpypi dist/*

Useful Links:

Packaging Python Projects: https://packaging.python.org/en/latest/tutorials/packaging-projects/#uploading-the-distribution-archives

django-accounts-package's People

Contributors

muhammadalgshy avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.