Accessing user metadata using a flat field name

I’m trying to integrate Auth0 with an application (TalentLMS) using OpenID Connect that expects to find user metadata such as given_name, family_name, etc in the top-level JSON string. Specifically the OpenID Connect mechanism of the software just says “tell me the (top-level) attribute that stands for the user first name and I’ll get it from the token”.

However, when I look at the JSON structure of a user with user metadata, the user_metadata that might contain first name, etc is in a sub-structure under “user_metadata”.

Is there a way to get Auth0 to return user metadata directly as part of the ID Token and not as a substructure - at least for that particular application? I can’t modify this (and I’m sure a bunch of other apps) to be “smarter” in that regard. Or otherwise am I misunderstanding the use of user metadata.

Okay, I’ve just found the “rules” section and written a rule to copy user metadata into the token.

What I found interesting is that there are a lot of rule templates, but this is the simplest one most people will want so I think it should be in one of the default templates?

function (user, context, callback) {
  if (context.clientName === 'TalentLMS' && user.user_metadata) {
    var copy_attrs = ["given_name", "family_name"];
    for (var j = 0; j < copy_attrs.length; j++) {
      if (copy_attrs[j] in user.user_metadata) {
        user[copy_attrs[j]] = user.user_metadata[copy_attrs[j]];
      }
    }
  }

  callback(null, user, context);
}
1 Like

Thanks a lot @madumlao!

I’ll make sure to get this feedback relayed to appropriate product team!

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