Skip to main content

BaseApp Auth

Project description

BaseApp Auth

Usage

This project includes:

  • API endpoints for authentication and account management
  • default User model

Abstract user model

AbstractUser is an abstract Django user model implementation. It provides a default implementation of User model and can be extended in the target Django app. The attached test project contains a concrete implementation of User class for demo purposes.

Authentication endpoints

In the rest_framework/ directory you can find a implementation of account-related endpoints: login, signup, forgot-passowrd, change-email. Authentication (login) is implemented in a few different modes that can be picked depending on project preference/requirements. In testproject/urls.py you'll find DRF routing set up for each of supported modes with unit tests for each mode:

  • Authentication with Simple AuthToken
  • Authentication with JWT
  • Authentication with MFA and Simple AuthToken
  • Authentication with MFA and JWT

Utilities

Demo

There is a test project with a complete demo set up.

Installation

Add to requirements of yor project (replacing everything inside brackets):

baseapp-auth @ git+https://github.com/silverlogic/baseapp-backend.git@v0.1#subdirectory=baseapp-auth

Settings

Add the app to your project INSTALLED_APPS:

INSTALLED_APPS = [
    ...
    "baseapp_auth",
]

Set the Django auth user model to the concrete model of your app:

AUTH_USER_MODEL = "testapp.User"

If you want to use JWT authentication, add the corresponding authentication backend:

REST_FRAMEWORK = {
    "DEFAULT_AUTHENTICATION_CLASSES": (
        "rest_framework_simplejwt.authentication.JWTAuthentication",
        # ...
    )
}

I you want to use JWT authentication, set the related JWT settings (e.g. the claims serializer):

SIMPLE_JWT = {
    # It will work instead of the default serializer(TokenObtainPairSerializer).
    "TOKEN_OBTAIN_SERIALIZER": "testproject.testapp.rest_framework.jwt.serializers.MyTokenObtainPairSerializer",
    # ...
}
JWT_CLAIM_SERIALIZER_CLASS = "baseapp_auth.rest_framework.users.serializers.UserBaseSerializer"

There is a constance config for password expiration interval:

CONSTANCE_CONFIG = OrderedDict(
    [
        (
            "USER_PASSWORD_EXPIRATION_INTERVAL",
            (
                365 * 2,
                "The time interval (in days) after which a user will need to reset their password.",
            ),
        ),
    ]
)

There is an optional scheduled task that can be configured for notifying that the user's password has expired:

CELERY_BEAT_SCHEDULE = {
    "notify_is_password_expired": {
        "task": "baseapp_auth.tasks.notify_users_is_password_expired",
        "schedule": "...",
        "options": "...",
    },
}

How to delevop

General development instructions can be found in main README

Other Settings

BA_AUTH_PRE_AUTH_TOKEN_EXPIRATION_TIME_DELTA: datetime.timedelta

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

baseapp-auth-0.2.3.tar.gz (36.6 kB view details)

Uploaded Source

File details

Details for the file baseapp-auth-0.2.3.tar.gz.

File metadata

  • Download URL: baseapp-auth-0.2.3.tar.gz
  • Upload date:
  • Size: 36.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for baseapp-auth-0.2.3.tar.gz
Algorithm Hash digest
SHA256 c5b8ddc16e6e21e131f17cf2a58f1c806671ccd5034de228adc7d35d030df7c2
MD5 c160d7777e54c307e627d78263fa61ff
BLAKE2b-256 6eefbee1a3620a54617fd976796b8548d60a2f4efad498a10d3d130235584209

See more details on using hashes here.

Supported by

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