Django Auth0 Read user_metadata

After following auth0’s quick start, I can’t seem to find a way to access the logged-in user’s “user_metadata” in django. Anyone else tried to achieve this with django and can share how?

I followed the following quick start:

Hey there!

Hmm it’s indeed not documented there. Let me do a bit of research and get back to you once I find something

Have you tried accessing request.user object properties and looking there?

Yes, I’m not seeing anything relevant there. I also tried to add a Rule in order to inject the value from the user_metadata into the accessToken with a custom namespace, and then to request it as one of the scopes/claims. Can’t see it made any difference, the data is also not in the UserSocialAuth.extra_data field.

I finally managed to do it. Follow these steps:

  1. Add a rule in Auth0’s interface, adding the desired metadata parameter to the idToken, as shown in the bottom of this page.
  2. Add the same claim including its namespace to the claims in django, the SOCIAL_AUTH_SCOPE (not SOCIAL_AUTH_AUTH0_SCOPE as shown in the quickstart) list in the settings made it for me.
  3. Extending the get_user_details function as shown in the django quickstart guide and adding the new relevant fields to the EXTRA_DATA mapping.

Then it worked for me, and the variable made its way into user.social_auth.get(provider=‘auth0’).extra_data.

Hope that would help other people.

1 Like

Wohoo! Glad to hear that and thanks for sharing with the rest of community!