Skip to content

enabling redirect to login while is already loaded #4

@sdementen

Description

@sdementen

currently, if a user has logged in okta but his session has expired, the dash app is not updated anymore as the calls to /_dash-... are receiving a redirect (302) they cannot manage.
I have hacked the following solution that appears to work:

  1. add an element of type dcc.Location(refresh=True, id="URL_OUT"), in the app layout
  2. trigger a change on this element when Dash is sending a /_dash-update-component and the session is not authorized. For this, change in the "login_request" (https://github.com/fspijkerman/dash-okta-auth/blob/master/dash_okta_auth/okta_oauth.py#L45) from
    def login_request(self):
        # send to okta auth page
        return redirect(url_for("okta.login"))

to

    def login_request(self):
        # send to okta auth page
        if request.path.startswith("/_dash-update-component"):
            import json
            return json.dumps({"response": {"URL_OUT": {"href": "http://127.0.0.1:8051/login/okta"}}, "multi": True})
        return redirect(url_for("okta.login"))

Today, the ID of the dcc.Location is hardcoded but it could be passed as a configuration parameter.

Is this a reasonable fix ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions