Unable to capture the users running webapp properly

Anony123
Level 1
Unable to capture the users running webapp properly

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

0 Kudos
1 Reply
AlexT
Dataiker

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)
});
0 Kudos