Skip to content

Leveraging dash-auth role-based access control #1157

@gtauzin

Description

@gtauzin

Have you already looked into this topic?

  • I've reviewed the Vizro documentation for any relevant information
  • I've searched through existing issues for similar questions
  • I've already searched online (e.g., Dash documentation) but couldn’t find anything helpful

Question

Hi everyone 👋!

I am looking into authentification and role-based access control of my vizro apps. I went for dash-auth and it seems it has everything I need.

When it comes to group-based access control, dash-auth offers the protected and protected_callback functions and I am looking into how to integrate them nicely into vizro.

My idea on how to approach it is to do the following:

  1. Create a vizro Modal component wrapping dbc.Modal
  2. Create two Modal instances at the vm.Dashboard level to be opened whenever the user is unauthentified (with a login button) or missing permissions (with a logout / sign in with another account button).
  3. Subclass vm.Action into a ProtectedAction that will call the protected function to open the right modal based on the authorization error (or none of them if the user is authorized)
  4. Use ProtectedAction in place of vm.Action all over my app (by calling add_type appropriately)

I am having some issues with add_type (see below) for which I would really appreciate your help, but I would mostly like to know what you think about this approach.

Code/Examples

I have made a simple example of my ProtectedAction class on PyCafe that roughly implements the protection logic. There is no Modal in that example, so we expect the Show histogram button to not do anything if clicked without permissions.

However, I am running into a pydantic issue when calling add_type:

pydantic.errors.PydanticUserError: `Tag` not provided for choice {'type': 'definition-ref', 'schema_ref': 'app.ProtectedAction:153118520'} used with `Discriminator`

Note that before trying to write a ProtectedAction, I have tested that simply wrapping protected within the action worked:

@capture("action")
def show_plot_action():
    def func():
        return px.histogram(df, x="sepal_width", color="species")

    return protected(unauthenticated_output=None, missing_permissions_output=None, groups=["Admin"])(func)()

Thanks a lot for your help! :)

Which package?

vizro

Code of Conduct

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions