Skip to main content

A Django app that handles the communication between the IDP and the products for the authorization of users.

Project description

Django IDP User

pypi-badge build-status-image package-status github-last-commit


Installation

  1. Install the package:

    pip install django-idp-user
    

    If you want to use the async version of the package, you can install it with the async extra:

    pip install django-idp-user[async]
    
  2. Add idp_user to your INSTALLED_APPS:

    INSTALLED_APPS = [
        # ...
        'idp_user',
    ]
    
  3. Add the settings of the app in settings.py like this:

    AUTH_USER_MODEL = 'idp_user.User'
    
    IDP_USER_APP = {
        "IDP_ENVIRONMENT": "staging/production/etc.",
        "APP_IDENTIFIER": "str",
        "ROLES": "path.to.roles_choices",
        "FAUST_APP_PATH": "backend.kafka_consumer.app",
        "USE_REDIS_CACHE": True,
        "IDP_URL": "idp_url",  # Optional
        "APP_ENTITIES": {
            "<entity_type>": {
                "model": "<path.to.entity_type.model>",
                "identifier_attr": "<field_name>",
                "label_attr": "<field_name>",
            }
        },
    }
    
    REST_FRAMEWORK = {
        'DEFAULT_SCHEMA_CLASS': 'drf_spectacular.openapi.AutoSchema' or 'idp_user.schema_extensions.AutoSchemaWithRole',
        'DEFAULT_AUTHENTICATION_CLASSES': (
            'idp_user.auth.AuthenticationBackend',
        ),
    }
    
    SPECTACULAR_SETTINGS = {
        'DEFAULT_AUTHENTICATION_CLASSES': (
            'idp_user.schema_extensions.BearerTokenScheme',
        ),
        'SERVE_AUTHENTICATION': ()
    }
    
    # Kafka Related
    KAFKA_ARN = "<aws_kafka_arn>"  # Encoded in base64
    KAFKA_AWS_ACCESS_KEY_ID = "<access_key_id>"
    KAFKA_AWS_SECRET_ACCESS_KEY = "<secret_access_key_id>"  # Encoded in base64
    AWS_S3_REGION_NAME = "<region_name>"
    
  4. Create the database tables for the app by running the following command:

    python manage.py migrate
    

Async Support

Django version 4.1.1 is required for async support.

To use the async version of the package, you need to add the async extra when installing the package:

pip install django-idp-user[async]

If you are using Channels for websockets, you can use the IDPChannelsAuthenticationMiddleware like so:

from channels.routing import ProtocolTypeRouter, URLRouter
from idp_user.auth import IDPChannelsAuthenticationMiddleware

application = ProtocolTypeRouter({
    "websocket": IDPChannelsAuthenticationMiddleware(
        AuthMiddlewareStack(
            URLRouter(
                # ...
            )
        )
    ),
})

Settings Reference

  • IDP_ENVIRONMENT

    • The environment of the IDP with which the app will communicate.
    • Used mainly for the Kafka Consumer & Producer.
  • APP_IDENTIFIER

    • The app identifier, as defined in the IDP.
  • ROLES

    • The path to the roles choices.
  • FAUST_APP_PATH

    • The path to the Faust app.
  • IDP_URL

    • The URL of the IDP, used for local development, or when using the IDP as an Authentication Backend.
  • USE_REDIS_CACHE

    • If True, the cache will be used
    • When developing locally, you can leave this as False.
  • APP_ENTITIES

    • This dict links the AppEntityTypes declared on the IDP for this app to their actual models, so that they can be used for authorization purposes. In the value dicts, the attributes that will be used as the identifier and label are declared as well.

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

django_idp_user-3.0.1.tar.gz (19.1 kB view details)

Uploaded Source

Built Distribution

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

django_idp_user-3.0.1-py3-none-any.whl (32.0 kB view details)

Uploaded Python 3

File details

Details for the file django_idp_user-3.0.1.tar.gz.

File metadata

  • Download URL: django_idp_user-3.0.1.tar.gz
  • Upload date:
  • Size: 19.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.21

File hashes

Hashes for django_idp_user-3.0.1.tar.gz
Algorithm Hash digest
SHA256 2300ce7bd4b567e0c94516582a41959d401faee03de70aa1e2e21e0dc2917fef
MD5 d976bf653e4104ca6e96f6fa8e374d82
BLAKE2b-256 4a88991953fd68683dc94718f19d214c5d4a6beca9a61d09c8de8549d3bbfa35

See more details on using hashes here.

File details

Details for the file django_idp_user-3.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for django_idp_user-3.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ef48486d2bad3cbb1041e5527aef19fc479df19cea11f52e01fe03719f423a17
MD5 a3c31f9dc7d9e10af2058c431cc6f645
BLAKE2b-256 b796d7ccea6a50a64edda46a67ff4b2d99c18263a2bc069c685badefe05756dd

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