How to hold Plotly dash app behind protected route
I'll share a few resources I found researching the question:
- Dash provides a library named
dash-auth
, which you can install usingpip install dash-auth
- Once you install the library, you'll be able to use
import dash_auth
, and you'll notice sub-modules for HTTP Basic Auth, OAuth, and "PlotlyAuth". "PlotlyAuth" has been deprecated, according to the text infrom dash_auth.plotly_auth import deprecation_notice
- The source code for this module appears to be https://github.com/plotly/dash-auth
- Documentation is available at https://dash.plotly.com/authentication and a promotional page is available at https://plotly.com/dash/authentication/
- Presumably, JWT can be integrated using Flask's
Response.set_cookie
. Here are details about that approach, notice the author usesrep.set_cookie('custom-auth-session', username)
- There's an example on Github which uses Dash, Flask, and Flask-Login. This configuration also exists in a separate StackOverflow question. However, this library doesn't supports JWT. You may be able to achieve a similar architecture using the Flask-JWT-Extended library.