✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
⚾️ It's finally Baseball season! Root for the home team... & Register for our Sports Analytics Webinar!

Get login user name

I tried the Dash Basic Auth and it worked well, but I am wondering how to get login user name so I can track individual users. Thanks!

Here is how the username and password are parsed from the original Authorization header: https://github.com/plotly/dash-auth/blob/6a03928b346e52494841c72b95de9a1f627888dc/dash_auth/basic_auth.py#L12-L17
You might be able to use this logic inside your callback, although I haven’t tried this.

That worked. Thanks!


Could you share your solution? Thx :grinning:

1 Like

I would also be really happy, if you can share your idea!
Thanks in advance!

I think the point is that you can simply make a very similar function if you need the username or password. Something like:

import flask
import base64
def get_client_username_and_password():
    header = flask.request.headers.get('Authorization', None)
    if not header:
        return None, None
    username_password = base64.b64decode(header.split('Basic ')[1])
    username_password_utf8 = username_password.decode('utf-8')
    username, password = username_password_utf8.split(':')
    return username, password