Auth0 Home Blog Docs

Accessing user metadata using a flat field name

sso-integration
#1

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”.

http://support.talentlms.com/knowledgebase/articles/1817146-how-to-configure-sso-with-openid-connect

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.

#2

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
#3

Thanks a lot @madumlao!

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

closed #5

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