Package: django-accounts-package
Account PackageTable of ContentsAboutGetting StartedPrerequisitesInstallingSettingsRunTestBuild the packageAboutThe 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.PrerequisitesWhat things you need to install the software and how to install them:Python Version: 3.8 or 3.9 Enviroment: PipenvInstallingA step by step series of examples that tell you how to get a development
env running.Navigate to your django projectprojectname(Linux, windows)$cdprojectnameInstall python packages$python-mpipenvinstalldj-rest-auth$python-mpipenvinstalldjango-allauth$python-mpipenvinstalldjangorestframework$python-mpipenvinstalldjangorestframework-simplejwtSettingsImport settings from accounts in settings.py:fromaccounts.configurationsimport*Add accounts to installed apps:INSTALLED_APPS=[...'accounts',]+ACCOUNTS_APPSAdd 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_authproviderGOOGLE_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_usersSUPER_USERNAME="email"SUPER_PASSWORD="password"Customizable SettingsAUTHENTICATION_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 siteSITE_ID=1# Set your site IDACCOUNT_USER_MODEL_USERNAME_FIELD=NoneACCOUNT_EMAIL_REQUIRED=True# Use email instead of usernameACCOUNT_USERNAME_REQUIRED=False# Disable Uesrname field for authenticationACCOUNT_AUTHENTICATION_METHOD='email'# Use email to authenticateACCOUNT_ADAPTER='accounts.adapter.MyCustomAdapter'SOCIALACCOUNT_ADAPTER='accounts.adapter.MyCustomSocialAdapter'REST_USE_JWT=True# User JWT instead ot TokenJWT_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 authenticationUSER_NOPASSWORD=True# You can Create User without password.USER_DELETE=False# Allow User Deletion in admin panel# REST FRMEWORK SettingsREST_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 SettingsfromdatetimeimporttimedeltaSIMPLE_JWT={'ACCESS_TOKEN_LIFETIME':timedelta(minutes=30),}RunInstall all packages$python-mpipenvinstallor$pythonmanage.pyinit_pkgRun Database Migration$pythonmanage.pymigrateInitiate Super user$pythonmanage.pyinit_usersInitiate Authentication Social Applications$pythonmanage.pyinit_authproviderRun Django Server$cdprojectname/$pythonmanage.pyrunserverTestAPIsGoogle Auth: Go tohttp://localhost:8000/auth/google(Use the Access
Token)Microsoft Auth: Go tohttp://localhost:8000/auth/ms(Use the Access
Token)Check Auth: Go tohttp://localhost:8000/auth/secureUseful Links:Google Playground:https://developers.google.com/oauthplayground/