Skip to main content

Pangea Django Setup

Use Django as your authentication backend in a few simple steps.

Install the Pangea SDK

Run the following command

pip install pangea-django

Set up AuthN with Pangea

Go to the Pangea AuthN service and step through the dialogs. You will need to collect the auth token you created, the domain and the hosted login link for later. Also set the redirect (callback) link under Settings/General/Redirect(callback) Settings, this is where the hosted flow will send the user once they are logged in.

Environment Variables

Set up the environment variables (Instructions) PANGEA_AUTHN_TOKEN and PANGEA_DOMAIN with your project token configured on the Pangea User Console (token should have access to AuthN service Instructions) and with your Pangea domain. Note that the Django integration only need the client token and not the service token. The client token has fewer privileges and is therefore safer to use. If you are using Pangea AuthN endpoints outside this integration, you may need the full service token.

Django Settings

Modify the following values in the settings.py of your Django project

  • Add 'pangea_django.PangeaAuthMiddleware' to the MIDDLEWARE. You can keep or remove the standard Django contrib auth middleware.
  • Ensure you have sessions set up, you should have this already. See Using Django Sessions
  • Ensure you have a working user model. Typically this just means enabling a DB. You can use a SQLite DB to get up and running quickly. See Django Databases#SQLite
  • This auth backend is designed to use the hosted login method provided by Pangea. You will need to do the following to authenticate
    • From the Django view(s) where you want to kick off a login process, redirect to your hosted login link.redirect(f"<link you copied from the Pangea Console>?state={generate_state_param(request)}"). Note the use of the generate_state_param helper function from the pangea_django module. This creates a secure state param for this purpose.
    • From the Django view where the user was redirected from the login process, use the pangea_django.PangeaAuthentication class to authenticate the request PangeaAuthentication().authenticate(request=request). If authentication was successful you will get a UserModel object representing the user (None otherwise).
    • From views where you wish to check if the user is logged in you can use the normal Django patterns of checking request.user.is_authenticated or using the login_required decorator etc.
    • You can log the user out with PangeaAuthentication().logout(request)
    • The authenticate call will create a user based on the email(username) address in Pangea if that user does not exist, it will also populate basic info (first name, last name, email address and last login time).
    • The user will be logged out automatically once the user's active token has expired and their refresh token can no longer refresh the session.

Metadata

Release files for pangea-django 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pangea-django 1.0.1
File Size Uploaded Provenance
pangea_django-1.0.1.tar.gz 4.2 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for pangea-django 1.0.1
File Interpreter ABI Platform
pangea_django-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 9.0 kB

Release files / pangea_django-1.0.1.tar.gz

Download URL pangea_django-1.0.1.tar.gz
Size 4.2 kB
Tags Source
SHA-256 checksum
How to use checksums
b9cb9f97207c647bda4a45ef79ff981226740af26e2386fefd19a0c9e5b40461
BLAKE2b-256 checksum
How to use checksums
6edbaabe38535d1053f884a1efa137ab75cb0ccc89b29f28782816fb1de5040c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.2 CPython/3.8.19 Linux/5.15.146+

Release files / pangea_django-1.0.1-py3-none-any.whl

Download URL pangea_django-1.0.1-py3-none-any.whl
Size 4.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5a1a8a7236db3f44d75e3cb0d9954e4bc8d2acb3b92e0b9647ae6cf2058cd6c9
BLAKE2b-256 checksum
How to use checksums
3cb2cd180c1b5513644585b5a101435c069321644c97a0a5b62075a5aa1e4253
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.2 CPython/3.8.19 Linux/5.15.146+

Security for pangea-django 1.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page