Skip to main content

An open source, one-stop authentication framework for Django and ready for production.

Project description

Contributors

Issues


Django Auth Framework

An open source, one-stop authentication framework for Django and ready for production.

Table of Contents

  1. About The Project
  2. Getting Started
  3. API Endpoints and Examples
  4. Contributing
  5. License

About The Project

Django Auth Framework is an open source, one-stop framework for Django applications providing the most essential APIs for authentication and authorization. APIs also cover Oauth2 protocol, social login and user management with options allows to easily customize and override for working on most scenarios. It supports multiple authentication ways to make your auth server scalable from a monolithic server using Token/Session authentication to service mesh such like Istio on Kubernetes Cluster with JWT authentication.

This framework was originally developed by me to help Django projects in our company fast setup. Now, it has scaled our service over a million users. I am happy to open soucre this project, hope it is helpful in your projects or startups

Built With

Features

  • Production-ready, optimized by reducing unnecessary queries write to db during authentication and authorization.
  • Extends Django OAuth Toolkit's default Oauth2Validator to allow authorization with multiple types of credentials like email, phone number.
  • Pure RESTFUL API endpoints implemented with Django REST framework, this framework doesn't use any traditional Django components(eg: forms, html).
  • Supports the most popular social login(Google,Apple and Facebook) followed by up to date guidelines, users at frontend can be authorized by either id_token, code or access_token.
  • NO FULL DOCUMENTATION atm.

Getting Started

To get a local copy up and running follow these simple steps.

Installation

pip install django-auth-framework

Configurations

  1. Edit settings.py file:

     #in your my_auth/models.py
      # from auth_framework.models import AbstractUser
      # class MyUser(AbstractUser):
      #     custom_fields ...
     AUTH_USER_MODEL = 'my_auth.MyUser'
    

    or just try with

     AUTH_USER_MODEL = 'auth_framework.User'
    

    add required apps and configuration for rest_framework:

    # ...
    REQUIRED_APPS = [
         'rest_framework',
         'oauth2_provider',
         'auth_framework',
    ]
    LOCAL_APPS = [
         'my_auth'
    ]
    INSTALLED_APPS += REQUIRED_APPS
    INSTALLED_APPS += LOCAL_APPS
     # ...
     REST_FRAMEWORK = {
     'DEFAULT_AUTHENTICATION_CLASSES': (
         'oauth2_provider.contrib.rest_framework.OAuth2Authentication',
         'rest_framework.authentication.SessionAuthentication',
    
     ),
     }
    

    if you need other unique fields: email or phone_number not justusernameas credentials:

     AUTHENTICATION_BACKENDS = [
         "auth_framework.backends.auth_backends.AuthenticationBackend",
     ]
     
     OAUTH2_PROVIDER = {
         "OIDC_ENABLED": True,
         "OIDC_RSA_PRIVATE_KEY": os.environ.get('OIDC_RSA_PRIVATE_KEY'),
         'SCOPES': {
             "openid": "OpenID Connect scope",
             'read': 'Read scope',
             'write': 'Write scope',
         },
         'OAUTH2_VALIDATOR_CLASS': 'auth_framework.oauth.oauth2_validators.OauthValidator',
         'OAUTH2_BACKEND_CLASS': 'auth_framework.oauth.oauth2_backends.OAuthLibCore',
     }
    
  2. Edit the urls.py:

    from django.contrib import admin
    from django.urls import path, include
    
    urlpatterns = [
       path('admin/', admin.site.urls),
       path('account/', include('auth_framework.urls'))
    ]
     
    
  3. Sync Database and createsuperuser:

    python manage.py migrate
    python manage.py createsuperuser
    
  4. Login to the admin page http://localhost:8000/admin/oauth2_provider/application/add/ and add a default Application. if it's only open to your first party apps, then just choose Resource owner password-based as the grant type (No one likes to login with password but still having a redirect web page on a native app)

  5. [Optional] Configure of Social Adapters: in most scenarios, you only need to create one client id/secret for each social provider. For security and performance, it will look up those environment variables during making Oauth request calls instead of creating many key pairs to the database:

    GOOGLE_CLIENT_ID=*********.apps.googleusercontent.com
    GOOGLE_CLIENT_SECRET=**********
    FACEBOOK_CLIENT_ID=**********
    FACEBOOK_CLIENT_SECRET=**************
    APPLE_CLIENT_ID=com.team.project
    APPLE_CLIENT_SECRET=**************
    

    If this is not your thing, consider to use allauth-django

API Endpoints and Examples

Postman

Contributing

If you have improvements to Django Auth Framework, just send a pull request:

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Or leave a comment in our Issues

License

Distributed under the BSD License. See LICENSE for more information.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-auth-framework-2.0.7.tar.gz (43.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_auth_framework-2.0.7-py3-none-any.whl (46.7 kB view details)

Uploaded Python 3

File details

Details for the file django-auth-framework-2.0.7.tar.gz.

File metadata

  • Download URL: django-auth-framework-2.0.7.tar.gz
  • Upload date:
  • Size: 43.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for django-auth-framework-2.0.7.tar.gz
Algorithm Hash digest
SHA256 31f0b0a04f2b85292490db429ffe4b9ecbce873c1037bd9b42fb1d8e1cf2f516
MD5 99c6de36eba6b5e5ae4cf90165b3163e
BLAKE2b-256 20d3fc0ec2f9d3a5a42523aaef3e74610596f978c6048d5ef3f30c69a2e49e51

See more details on using hashes here.

File details

Details for the file django_auth_framework-2.0.7-py3-none-any.whl.

File metadata

File hashes

Hashes for django_auth_framework-2.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 1cf49501c688451b3039f8c49038f2dfd3e30e41d57ec2efad570c1fcc255d22
MD5 0a6e87a9dcf680acf19f2cec7b2374c3
BLAKE2b-256 3ba46f5597b7126a70f6a94779494fe3e8a7320dde5ac2d73500f133c57a8e8f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page