Unable to capture the users running webapp properly

Anony123
Anony123 Registered Posts: 3

Hi Team,

I am trying to capture the user who is running the webapp as it is shared environment. sometimes it is capturing correctly and sometimes not. It is just showing the one you who started the webapp and displaying the same for every run even some other user runs it. I want to capture the user who is running the dataiku webapp.

Here is my code:

import dataiku

client= dataiku.api_client()

auth_info= client.get_auth_info()

user= auth_info[‘authIdentifier’]

print(user)


Operating system used: Windows


Operating system used: Windows

Tagged:

Answers

  • Alexandru
    Alexandru Dataiker, Dataiku DSS Core Designer, Dataiku DSS ML Practitioner, Dataiku DSS Adv Designer, Registered Posts: 1,226 Dataiker
    edited July 17

    Hi @Anony123
    ,
    If you have python backend to your webapp you can use the following to obtain the user that currently viewing the webapp. Not the "run as" user.

    Screenshot 2023-07-13 at 8.05.11 AM.png

    Screenshot 2023-07-13 at 8.06.44 AM.png

    python code:
    
    @app.route('/get_current_user')
    def get_user():
        request_headers = dict(request.headers)
        auth_info_browser = dataiku.api_client().get_auth_info_from_browser_headers(request_headers)
        logging.info((auth_info_browser))
        return auth_info_browser
    
    
    JavaScript code:
    
    $.getJSON(getWebAppBackendUrl('/get_current_user'), function(data) {
        console.log('Received data from backend', data)
        const output = $('<pre />').text('Backend reply: ' + JSON.stringify(data));
        $('body').append(output)
    });
Setup Info
    Tags
      Help me…