pangea-django


Namepangea-django JSON
Version 1.0.0 PyPI version JSON
download
home_pagehttps://github.com/pangeacyber/pangea-python
SummaryPangea Authentication Addon for Django
upload_time2023-12-20 22:37:18
maintainer
docs_urlNone
authorGovind Salinas
requires_python>=3.8.0,<4.0.0
licenseMIT
keywords pangea django autnn
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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](https://console.pangea.cloud/service/authn) 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](https://pangea.cloud/docs/getting-started/integrate/#set-environment-variables)) `PANGEA_AUTHN_TOKEN` and `PANGEA_DOMAIN` with your project token configured on the Pangea User Console (token should have access to AuthN service [Instructions](https://pangea.cloud/docs/getting-started/configure-services/#configure-a-pangea-service)) 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](https://docs.djangoproject.com/en/4.2/topics/http/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](https://docs.djangoproject.com/en/4.2/ref/databases/#sqlite-notes)
* 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.


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/pangeacyber/pangea-python",
    "name": "pangea-django",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8.0,<4.0.0",
    "maintainer_email": "",
    "keywords": "Pangea,Django,AutnN",
    "author": "Govind Salinas",
    "author_email": "govind.salinas@pangea.cloud",
    "download_url": "https://files.pythonhosted.org/packages/b0/11/5384ae793ffe41dd6800023c465beac3d355302eac4619c342327c301c59/pangea_django-1.0.0.tar.gz",
    "platform": null,
    "description": "# Pangea Django Setup\n\nUse Django as your authentication backend in a few simple steps.\n\n## Install the Pangea SDK\n\nRun the following command\n\n```\npip install pangea-django\n```\n\n## Set up AuthN with Pangea\n\nGo to the [Pangea AuthN service](https://console.pangea.cloud/service/authn) 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.\n\n## Environment Variables\nSet up the environment variables ([Instructions](https://pangea.cloud/docs/getting-started/integrate/#set-environment-variables)) `PANGEA_AUTHN_TOKEN` and `PANGEA_DOMAIN` with your project token configured on the Pangea User Console (token should have access to AuthN service [Instructions](https://pangea.cloud/docs/getting-started/configure-services/#configure-a-pangea-service)) and with your Pangea domain.\nNote 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.\n\n## Django Settings\n\nModify the following values in the settings.py of your Django project\n\n* Add `'pangea_django.PangeaAuthMiddleware'` to the `MIDDLEWARE`. You can keep or remove the standard Django contrib auth middleware.\n* Ensure you have sessions set up, you should have this already. See [Using Django Sessions](https://docs.djangoproject.com/en/4.2/topics/http/sessions/)\n* 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](https://docs.djangoproject.com/en/4.2/ref/databases/#sqlite-notes)\n* This auth backend is designed to use the hosted login method provided by Pangea. You will need to do the following to authenticate\n    - 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.\n    - 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).\n    - 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.\n    - You can log the user out with `PangeaAuthentication().logout(request)`\n    - 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).\n    - 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.\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Pangea Authentication Addon for Django",
    "version": "1.0.0",
    "project_urls": {
        "Homepage": "https://github.com/pangeacyber/pangea-python",
        "Repository": "https://github.com/pangeacyber/pangea-python"
    },
    "split_keywords": [
        "pangea",
        "django",
        "autnn"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "49cce76c660524ceea19df6b39fa9013dde7b1d48afc8d71695f96815b8e6ee0",
                "md5": "bac94b6f6769382ca75eedbe95c1dff9",
                "sha256": "99a1fe064966119c7a0092f81035265ca976c5ec8a1968efce4881efded0c582"
            },
            "downloads": -1,
            "filename": "pangea_django-1.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "bac94b6f6769382ca75eedbe95c1dff9",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8.0,<4.0.0",
            "size": 4433,
            "upload_time": "2023-12-20T22:37:17",
            "upload_time_iso_8601": "2023-12-20T22:37:17.148292Z",
            "url": "https://files.pythonhosted.org/packages/49/cc/e76c660524ceea19df6b39fa9013dde7b1d48afc8d71695f96815b8e6ee0/pangea_django-1.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b0115384ae793ffe41dd6800023c465beac3d355302eac4619c342327c301c59",
                "md5": "8fd97f3ac5972373af3c862a2b073643",
                "sha256": "d8dd847c11df0e6a3aab8e6605232837a2aaaec75f2f79e5946e7543b6362ee6"
            },
            "downloads": -1,
            "filename": "pangea_django-1.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "8fd97f3ac5972373af3c862a2b073643",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8.0,<4.0.0",
            "size": 3909,
            "upload_time": "2023-12-20T22:37:18",
            "upload_time_iso_8601": "2023-12-20T22:37:18.798801Z",
            "url": "https://files.pythonhosted.org/packages/b0/11/5384ae793ffe41dd6800023c465beac3d355302eac4619c342327c301c59/pangea_django-1.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-12-20 22:37:18",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "pangeacyber",
    "github_project": "pangea-python",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "pangea-django"
}
        
Elapsed time: 0.15384s