Skip to main content

Dash Cognito Auth

Project description

Dash Cognito Auth

Build + Test PyPI version

Dash Cognito Auth is a simple library using Cognito OAuth to authenticate and view a Dash app.

This Library uses Flask Dance and a modified version of Plotly's own dash auth for authentication.

This Library is heavily inspired by dash-google-oauth created by Lucas Chapin

Installation

$ pip install dash-cognito-auth

Basic Use

Authentication can be added to your Dash application using the CognitoOAuth class, i.e.

from dash import Dash
from flask import Flask
from dash_cognito_auth import CognitoOAuth

server = Flask(__name__)
server.config.update({
  'COGNITO_OAUTH_CLIENT_ID': ...,
  'COGNITO_OAUTH_CLIENT_SECRET': ...,
})

app = Dash(__name__, server=server, url_base_pathname="/")

additional_scopes = [...]
auth = CognitoOAuth(
   app,
   domain='mydomain',
   region='eu-west-1',
   additional_scopes,
   logout_url="/logout"
)

# your Dash app here :)
...

Example

This repository contains a simple Example App that demonstrates how to add Cognito authentication to your Dash app as well as the Login and Logout Flows.

Development

  • Check out the repository
  • Run pip install -r requirements.txt to install the package
  • Run pip install -r requirements-dev.txt to install additional dependencies for running the tests
  • If you want to run the Sample App or the end to end tests, it makes sense to deploy the Cloudformation Template in order to get a functioning User Pool + App Client
  • Run the tests locally
    • Use python -m pytest tests --ignore-glob "*end_to_end*" to exclude the integration / end to end tests that require a Cognito Setup
    • Use python -m pytest tests to run all tests

Integration Tests

There are integration tests against a Cognito User Pool + App Client, if you want to run those - either create a .env file with this content or set the environment variables with the same name.

# Credentials for the user in the user pool
COGNITO_USER_NAME=<username>
COGNITO_EMAIL=<email-that-must-match>
COGNITO_PASSWORD=<password>

# Connection between the app and the user pool
COGNITO_DOMAIN=<just-the-prefix>
COGNITO_REGION=<aws-region-of-the-cognito-userpool>
COGNITO_OAUTH_CLIENT_ID=<app-client-id>
COGNITO_OAUTH_CLIENT_SECRET=<app-client-secret>

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

dash_cognito_auth-0.0.5.tar.gz (39.9 kB view details)

Uploaded Source

Built Distribution

dash_cognito_auth-0.0.5-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file dash_cognito_auth-0.0.5.tar.gz.

File metadata

  • Download URL: dash_cognito_auth-0.0.5.tar.gz
  • Upload date:
  • Size: 39.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for dash_cognito_auth-0.0.5.tar.gz
Algorithm Hash digest
SHA256 306e07b25cc4e973b02ff824f22b33a2c4b1e7e20118a231c6e2a6a513e3bda3
MD5 4ca7dd41a407aaf0bf32ed84fbc38414
BLAKE2b-256 3cc854696ff06af9b03c574fa563ce53095c28f09437b767664b9baf7a68f2eb

See more details on using hashes here.

File details

Details for the file dash_cognito_auth-0.0.5-py3-none-any.whl.

File metadata

File hashes

Hashes for dash_cognito_auth-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 c1a80f1cad39fa961d917e11b9a29f41dd94930ccc858edc3915831f0afa8a93
MD5 ea1ea50d5c03e061f45bb4706f0e5f02
BLAKE2b-256 2d1cf95426d1a61df568f3615fa66642a24e11bcac7eaffc1422a2a7421a8ed8

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