Skip to main content

User profile management app

Project description

django-sso-app

User profile management app

Tech

Available configurations

  1. Backend only:

    Users profile informations are saved into a monolithic django project with django-sso-app installed. By logging in the client receives either JWT or Session Token.

    DJANGO_SSO_APP_SHAPE = 'backend_only'
    DJANGO_SSO_APP_BACKEND_DOMAINS = ['1.accounts.domain', ...]
    
  2. Backend + Api Gateway

    As point 1 but with an api gateway (i.e. kong) proxying authenticated requests to backend. By logging in the client receives a JWT crafted by backend with the api gateway generated secret.

    DJANGO_SSO_APP_SHAPE = 'backend_only_apigateway'
    DJANGO_SSO_APP_BACKEND_DOMAINS = ['1.accounts.domain', ...]
    DJANGO_SSO_APP_APIGATEWAY_HOST = 'kong'
    
  3. Backend + App

    User profile informations are saved into a django-sso-app instance, all protected django projects have django-sso-app installed and configured to authenticate users by django-sso-app generated JWT. By logging in the client receives a JWT crafted by backend.

    # Backend config
    DJANGO_SSO_APP_SHAPE = 'backend_app'
    DJANGO_SSO_APP_BACKEND_DOMAINS = ['1.accounts.domain', ..]
    
    # App config
    DJANGO_SSO_APP_SHAPE = 'app'
    DJANGO_SSO_APP_BACKEND_DOMAINS = ['1.accounts.domain', ...]
    
  4. Backend + App + Persistence

    As point 3 but protected projects keep user profiles aligned with django-sso-app instance.

    # Backend config
    DJANGO_SSO_APP_SHAPE = 'backend_app'
    DJANGO_SSO_APP_BACKEND_DOMAINS = ['1.accounts.domain', ...]
    
    # App config
    DJANGO_SSO_APP_SHAPE = 'app_persistence'
    DJANGO_SSO_APP_BACKEND_DOMAINS = ['1.accounts.domain', ...]
    
  5. Backend + App + Api Gateway

    As point 3 but with an api gateway proxying authenticated requests to django projects.

    Protected projects authenticate users by the X-Consumer-Username header set by api gateway. By logging in the client receives a JWT crafted by backend with the api gateway generated secret. All requests to protected services are authenticated by the JWT included in cookie (or header).

    # Backend config
    DJANGO_SSO_APP_SHAPE = 'backend_app_apigateway'
    DJANGO_SSO_APP_BACKEND_DOMAINS = ['1.accounts.domain', ...]
    DJANGO_SSO_APP_APIGATEWAY_HOST = 'http://kong:8001'
    
    # App config
    DJANGO_SSO_APP_SHAPE = 'app_apigateway'
    DJANGO_SSO_APP_BACKEND_DOMAINS = ['1.accounts.domain', ...]
    
  6. Backend + App + Persistence + Api Gateway

    As point 5 but protected projects keep user profiles aligned with django-sso-app instance.

    # Backend config
    DJANGO_SSO_APP_SHAPE = 'backend_app_apigateway'
    DJANGO_SSO_APP_BACKEND_DOMAINS = ['1.accounts.domain', ...]
    DJANGO_SSO_APP_APIGATEWAY_HOST = 'http://kong:8001'
    
    # App config
    DJANGO_SSO_APP_SHAPE = 'app_persistence_apigateway'
    DJANGO_SSO_APP_BACKEND_DOMAINS = ['1.accounts.domain', ...]
    

Note

Seamless switch between aforementioned configurations is mandatory in order to simplify scaling.

Setup

Config vars

Required

  • APP_DOMAIN

    i.e. accounts.example.com (default='localhost:8000')

  • DJANGO_SSO_APP_SHAPE

    One of backend_only, backend_only_apigateway, backend_app, app, app_persistence, app_apigateway, app_persistence_apigateway (default='backend_only').

Custom

  • COOKIE_DOMAIN

    JWT cookie domain (default=APP_DOMAIN)

  • I18N_PATH_ENABLED

    Enables i18n paths (default=True)

  • DJANGO_SSO_APP_APIGATEWAY_HOST

    Api gateway instance url (default='http://kong:8001')

  • DJANGO_SSO_APP_BACKEND_CUSTOM_FRONTEND_APP

    Custom frontend package (default=None)

  • DJANGO_SSO_APP_BACKEND_DOMAINS

    List of backend domains (default=[APP_DOMAIN])

Django

settings.py

from django_sso_app.settings import *

DJANGO_SSO_APP_SHAPE = env('DJANGO_SSO_APP_SHAPE', default='backend_only')
DJANGO_SSO_APP_APIGATEWAY_HOST = env('DJANGO_SSO_APP_APIGATEWAY_HOST', default='kong')
BACKEND_CUSTOM_FRONTEND_APP = env('BACKEND_CUSTOM_FRONTEND_APP', default=None)

LOCAL_APPS = []  # ...
LOCAL_APPS += DJANGO_SSO_APP_DJANGO_APPS

MIDDLEWARE = [
    ...
    'django_sso_app.core.backends.DjangoSsoAppLoginAuthenticationBackend',

    'django_sso_app.middleware.DjangoSsoAppAuthenticationMiddleware',
    ...
]

AUTHENTICATION_BACKENDS = [
    'django.contrib.auth.backends.ModelBackend',
] + DJANGO_SSO_APP_DJANGO_AUTHENTICATION_BACKENDS


AUTH_USER_MODEL = 'users.User'
LOGIN_URL = '/login/'

DRF_DEFAULT_AUTHENTICATION_CLASSES = [
    'rest_framework.authentication.TokenAuthentication'
    'django_sso_app.core.api.authentication.DjangoSsoApiAuthentication'
]

REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': DRF_DEFAULT_AUTHENTICATION_CLASSES,
    'DEFAULT_PERMISSION_CLASSES': (
        'rest_framework.permissions.IsAuthenticated',
    ),
    ...
}

urls.py

urlpatterns = []
api_urlpatterns = []
_I18N_URLPATTERNS = []

from django_sso_app.urls import (urlpatterns as django_sso_app__urlpatterns,
                                 api_urlpatterns as django_sso_app__api_urlpatterns,
                                 i18n_urlpatterns as django_sso_app_i18n_urlpatterns)
from django_sso_app.core.mixins import WebpackBuiltTemplateViewMixin

urlpatterns += django_sso_app__urlpatterns
api_urlpatterns += django_sso_app__api_urlpatterns
_I18N_URLPATTERNS += django_sso_app_i18n_urlpatterns

urlpatterns += [
    url(r'^i18n/', include('django.conf.urls.i18n')),
    url(r'^jsi18n/$', ...
]

_I18N_URLPATTERNS += [
    path('', WebpackBuiltTemplateViewMixin.as_view(template_name='pages/home.html'), name='home'),
    path('about/', WebpackBuiltTemplateViewMixin.as_view(template_name='pages/about.html'), name='about'),

    # Django Admin, use {% url 'admin:index' %}
    path(settings.ADMIN_URL, admin.site.urls),
]

if settings.I18N_PATH_ENABLED:
    urlpatterns += i18n_patterns(
        *_I18N_URLPATTERNS
    )
else:
    urlpatterns += _I18N_URLPATTERNS

...

Project details


Release history Release notifications | RSS feed

This version

0.6.1

Download files

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

Source Distribution

django-sso-app-0.6.1.tar.gz (189.7 kB view details)

Uploaded Source

Built Distribution

django_sso_app-0.6.1-py2.py3-none-any.whl (269.8 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file django-sso-app-0.6.1.tar.gz.

File metadata

  • Download URL: django-sso-app-0.6.1.tar.gz
  • Upload date:
  • Size: 189.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.3

File hashes

Hashes for django-sso-app-0.6.1.tar.gz
Algorithm Hash digest
SHA256 4514383b858b9c9a8a8102e59969edc788aeb6685d1ae79fdd2ade46a83b3bf5
MD5 3a23f51d0405d7af93463015379104df
BLAKE2b-256 7d9b37cb1031785cfba4c90cb86125eb089c4106f286adee360b8910e4682e8e

See more details on using hashes here.

File details

Details for the file django_sso_app-0.6.1-py2.py3-none-any.whl.

File metadata

  • Download URL: django_sso_app-0.6.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 269.8 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.3

File hashes

Hashes for django_sso_app-0.6.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 37c45195519b723f9673a5d6d7d25415262e01efddf3dcdf29923391ed3ef65b
MD5 24fa4b31a91acda0331e9cd128421849
BLAKE2b-256 5892faaed9595251ae471fc8c20f5d5ac8e85e057440fe08b1590dd14b4e328f

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