# Accessing user metadata using a flat field name

**URL:** <https://community.auth0.com/t/accessing-user-metadata-using-a-flat-field-name/19313>\
**Category:** Get Help\
**Tags:** sso-integration\
**Created:** [December 21, 2018, 6:48am UTC](https://community.auth0.com/t/accessing-user-metadata-using-a-flat-field-name/19313 "2018-12-21T06:48:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![madumlao](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/madumlao/32/10145_2.png) [@madumlao](https://community.auth0.com/u/madumlao)\
**Post date:** [December 21, 2018, 6:48am UTC](https://community.auth0.com/t/accessing-user-metadata-using-a-flat-field-name/19313/1 "2018-12-21T06:48:45Z")

</div>

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](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.

---

<div class="post-metadata">

**Author:** ![madumlao](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/madumlao/32/10145_2.png) [@madumlao](https://community.auth0.com/u/madumlao)\
**Post date:** [December 21, 2018, 7:25am UTC](https://community.auth0.com/t/accessing-user-metadata-using-a-flat-field-name/19313/2 "2018-12-21T07:25:23Z")

</div>

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?

```auto
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);
}

```

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [February 11, 2019, 6:34pm UTC](https://community.auth0.com/t/accessing-user-metadata-using-a-flat-field-name/19313/3 "2019-02-11T18:34:22Z")

</div>

Thanks a lot @madumlao!

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

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [February 26, 2019, 6:36pm UTC](https://community.auth0.com/t/accessing-user-metadata-using-a-flat-field-name/19313/5 "2019-02-26T18:36:56Z")

</div>

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