Get username for session_token with Shotgun Python API

In the ShotGrid Python API, if I create a ShotGrid connection with a session_token, is it possible to get the username that was used to generate that session_token?

Here’s is an example…

In [1]: import shotgun_api3

In [2]: sg = shotgun_api3.Shotgun("https://mysite.shotgunstudio.com/", login="jburnell", password="XXXXXXXXXX")

In [3]: session_token = sg.get_session_token()

In [4]: sg2 = shotgun_api3.Shotgun("https://mysite.shotgunstudio.com/", session_token=session_token)

Can I get the username (i.e. “jburnell”) from sg2?

1 Like

Very nice question! Would like to know it too :smiley:

My hack-around at the moment is to store the user name on my own, on disk or in windows-registry / QSettings. I don’t like it, but it does the job for now.

That’s what I have been doing, too. I dug around in the SGTK code a bit and saw it appears they’re storying the username as well.

But it is a bit odd, you know? The session token must be connected to a HumanUser somewhere.

I’ve been looking for a solution to this as well, but as far as I can tell there is no such method in the API. Furthermore, the lack of a whoami type API call becomes a bit of a roadblock if you’re incorporating the Autodesk Identity login method, which only gives you a session token back.

(though from memory it also gives you the username/email used to authenticate, but there’s not necessarily a relationship between this and the actual Shotgrid user)

If you ever find a solution to this, please let us know! :slight_smile:

Correction:
Looks like Identity flow gives you a straight up Bearer token: https://forge.autodesk.com/en/docs/oauth/v2/tutorials/get-3-legged-token/ and https://forge.autodesk.com/en/docs/oauth/v2/reference/http/gettoken-POST/

Problem of extracting the username (and other identity values) still remain though.