I'm sending the session token to my python backend...
# ask-a-descoper
s
I'm sending the session token to my python backend and I want to extract from the jwt_response (after the descope_client.validate_session call) the tenant id, user id, and the user's role. What's the syntax for that?
b
Copy code
jwt_response = descope_client.validate_session(session_token=session_token)
Also tagging @salmon-night-88354 that played with this in Python
f
s
Thanks, I see that I can validate if I already have those IDs, but I want to get all of those IDs after they've authenticated from descope
f
Oh if you want to get all those rather than validate whether a role exists, then you should be able to access that in the jwt_response. It is a dict. Did you try printing that. I dont remember exact syntax but it is returned in a dict (I think).
s
Yeah, it should be a dict, but I wanted to see what the keys were, I haven't gotten to the point where I've successfully validated it (Still working on backend stuff) so I haven't printed it, but I can do that if nobody knows
f
let me get that
s
Thanks Rishi
b
Wesley, the validate will return the jwt as a JSON.
The hierarchy will be:
Copy code
tenants: [
    "<tenant ID>": {
        "permissions":[
            "<Permission name>",
            ...
        ],
        "roles": [
            "<Role name>",
            ...
        ]
    },
    ...
]
@salmon-night-88354 worth adding this to the doc itself
f
Copy code
const jwt = await descopeClient.validateSession(session_token);
    Object.keys(jwt.token.tenants || []).forEach((tenantId) => {
      roles = roles.concat(jwt.token.tenants[tenantId].roles);
    });
b
userId will also be there as part of the
sub
key
s
Thanks for the detail! So jwt.token.sub for the userID? And for the tenants, it looks like you could potentially have one user under multiple tenants, correct?
f
Yes. A user can be part of more than one tenant
1
s
Cool. Also, I just realized that my cookie retrieval code didn't work. What is the name of the session and refesh token cookie?
f
DS and DSR