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:
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