fastapi-plotly-dash icon indicating copy to clipboard operation
fastapi-plotly-dash copied to clipboard

Question: did you test dash-addons like dash-uploader, and did you try to add an authentication mechanism?

Open sorenwacker opened this issue 2 years ago • 4 comments

Hi, I have tried the django-plotly-dash integration before, but some elements where difficult to get working. For example, the dash-uploader, needed some specific endpoints. And it was not so straigthforward to let the dash app know about the current user regarding authorization. I wonder, do you have experience with these things using fastapi-plotly-dash?

sorenwacker avatar Feb 15 '22 16:02 sorenwacker

Hi @sorenwacker !

First a note: While similarly named, this repo and django-plotly-dash serve different purposes, in that the Django project is an actual library to ease that integration, whereas this is just a sample project demonstrating how one might wire a Dash app into a FastAPI webserver.

With that said, to your specific question of "how to let the dash app know about the current user", I've solved this in a commercial project and it did require some non-trivial hoop jumping:

  1. Add session middleware to your FastAPI app and ensure it serializes sessions in a Flask-compatible way
  2. Add auth middleware to the FastAPI app which updates the session with user info
  3. From the Dash app, just use from flask import session and access the user info from the session

I'm a little swamped today, but if I have time later this week I'll come back an share an example (or just update this project to contain a few example setups, one of which shows how to wire in shared auth)

rusnyder avatar Feb 15 '22 17:02 rusnyder

That would be amazing. I implemented something like that, using a Flask server for the auth, before, for a scientific application, but looks quite bumpy, and I found some security issues as well.

sorenwacker avatar Feb 15 '22 17:02 sorenwacker

That would be amazing. I implemented something like that, using a Flask server for the auth, before, for a scientific application, but looks quite bumpy, and I found some security issues as well.

It's not terribly bumpy and definitely doable, but it is delicate from a security standpoint (relatively easy to misconfigure, IMO).

I'll keep you posted when I find the spare time 😄

rusnyder avatar Feb 15 '22 17:02 rusnyder

Hey! Any updates on this?

jorge243 avatar Jul 11 '22 14:07 jorge243