How to get user ID, cant do it with sub

Hello everyone,

For the operations I want, I need user ID. For example, view roles consists of a line as

conn.request("GET", "/{yourDomain}/api/v2/users/USER_ID/roles", headers=headers)

Stated by Auth0. Therefore, I need to access it. Now I can access nickname, email, name and similars with

id_token = token.get('id_token')
jwk_set = oauth.auth0.fetch_jwk_set()
user_info = jwt.decode(id_token, jwk_set)
print("------------------------")
print(user_info)
print("------------------------")

However, it does not consists of user ID. The id_token variable above is something like

eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6Ik55VnVhbjR3OTdoZG1NdkVOdGMyaCJ9.eyJuaWNrbmFtZSI6Im9hdGFzb3kxOSIsIm5hbWUiOiJvYXRhc295MTlAa3UuZWR1LnRyIiwicGljdHVyZSI6Imh0dHBzOi8vcy5ncmF2YXRhci5jb20vYXZhdGFyL2FhNWE3YzJjMWRiZDk2NjBmZWJlNzA5OTQzMWQzZTZjP3M9NDgwJnI9cGcmZD1odHRwcyUzQSUyRiUyRmNkbi5hdXRoMC5jb20lMkZhdmF0YXJzJTJGb2EucG5nIiwidXBkYXRlZF9hdCI6IjIwMjMtMTItMjRUMTA6NDI6NTguNDUzWiIsImVtYWlsIjoib2F0YXNveTE5QGt1LmVkdS50ciIsImVtYWlsX3ZlcmlmaWVkIjp0cnVlLCJpc3MiOiJodHRwczovL2NhZ2VkYS5ldS5hdXRoMC5jb20vIiwiYXVkIjoiNmthNElncGZXSDVqQmxmMHFDV1lTOVl3cmFFbGZzOU0iLCJpYXQiOjE3MDM0MTQ1ODAsImV4cCI6MTcwMzQ1MDU4MCwic3ViIjoiYXV0aDB8NjU2OGUxNTEwMzAwOTY2YWQzYjdkMTA2Iiwic2lkIjoiRlBSdzJlbmZ0MzVzYTlqb1pSdUszbWhlQkd4dVRwbHUiLCJub25jZSI6Inh0WlpFWGhYQ05KNnZhUnI0N1l6In0.SfI-4ObKcSS4dg3HE3dpe-yzGjbtc0YbSBgSuGGO-_FJT3XUJP–I49QYocjWDsi6ITk0Z7bx8MED19-k3CgTOuZiqMbiJsevHat7mozEsOmKlbC0TbQTSQdtsIOhD-rRYAqHSFzEsulC5zeLqV6SHUIm_GoRKXskVrolMj7lrWXldUe9gt-c9q–3c3GflcE10K2IL3DbP_kH_wFZ1kfUL456o9zESYXYu8BXc9oJ9IoNjJ3X1EsV6YFf7Pb5QR8FedqhIKQ62sScHciEAov43jc2oZLuev77Hj1GibSHz6mb6EwyNCLlW9jFeo-eMsX9EKxWgE2a1VGFIXuf5sXw

Which I quite feel unfamiliar.

Thanks for any help!

Hi @zedeleyici

Thanks for contacting the Auth0 Community.

The id_token variable that you pasted is the JWT (json web token). If you paste this into https://jwt.io/ you’ll see the sub value which will be the user_id. Please review https://auth0.com/docs/secure/tokens/json-web-tokens/validate-json-web-tokens the recommended approach is to use verify() as opposed to decode(). You should be able to extract the sub value and use this in the endpoint that you mentioned.

Warm regards

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.