# How to map extra SAML attributes from idP into Auth0 Profile

**URL:** <https://community.auth0.com/t/how-to-map-extra-saml-attributes-from-idp-into-auth0-profile/64049>\
**Category:** Get Help\
**Tags:** service-provider, metadata, saml\
**Created:** [June 7, 2021, 8:39pm UTC](https://community.auth0.com/t/how-to-map-extra-saml-attributes-from-idp-into-auth0-profile/64049 "2021-06-07T20:39:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![justinoc](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/justinoc/32/13081_2.png) [@justinoc](https://community.auth0.com/u/justinoc)\
**Post date:** [June 7, 2021, 8:39pm UTC](https://community.auth0.com/t/how-to-map-extra-saml-attributes-from-idp-into-auth0-profile/64049/1 "2021-06-07T20:39:04Z")

</div>

Hello–

I have Auth0 setup as a SAML sP for my application. I’ve used the SAML mappings under the Enterprise Connection editor to map the standard attributes like User ID, Name, First Name, Last Name, Email, etc.

However, the idP (Ping) is passing a couple of extra attributes for user office ID and user department ID. These are not part of the Auth0 user profile. I assumed I could map them to either user\_metadata or app\_metadata, but the mapper does not allow ‘dotting’ the attribute (e.g. "user\_metadata.office\_id’ : “office\_id” returns an error that ‘.’ is not allowed).

I’ve seen the topics for adding metadata to the response if Auth0 is the idP via rules, but thats for the reverse direction (Auth0 is the sP, Ping is the idP). Nothing to map extra attributes when logging in from an external idP. I see them in the Users RAW JSON, but can’t get them into a field that is readable by the application using the PHP-SDK. Alternatively, if I could read that Identity Provider Raw JSON from the app, that would suffice as well.

Everything else is working well on this setup, this is my last hurdle to overcome. Open to any suggestions here. Tanks!

---

<div class="post-metadata">

**Author:** ![justin.skiles](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/justin.skiles/32/13081_2.png) [@justin.skiles](https://community.auth0.com/u/justin.skiles)\
**Post date:** [June 24, 2021, 9:14pm UTC](https://community.auth0.com/t/how-to-map-extra-saml-attributes-from-idp-into-auth0-profile/64049/2 "2021-06-24T21:14:12Z")

</div>

Having the same issue. I’m using IdP-initiated SSO via SAML. An external IDP is sending SAMLResponse with some attributes that don’t map to OIDC compliant fields such as “userType” and “NPI”. I’m unsure of how to map these incoming SAML attributes into something like the user’s metadata. I’ve tried using rules, but I don’t see how the SAML attributes are accessible from the user or context objects.

---

<div class="post-metadata">

**Author:** ![justin.skiles](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/justin.skiles/32/13081_2.png) [@justin.skiles](https://community.auth0.com/u/justin.skiles)\
**Post date:** [June 24, 2021, 9:31pm UTC](https://community.auth0.com/t/how-to-map-extra-saml-attributes-from-idp-into-auth0-profile/64049/3 "2021-06-24T21:31:52Z")

</div>

I figured it out. It’s not intuitive, and I’m not sure it’s the best way, but it does seem to work.

In your Enterprise SSO connection for SAML SP, go to the Mappings tab and add the mappings for the fields that you want. Example:

```auto
  "user_type": "http://schemas.com/user_type",
  "npi": "http://schemas.com/npi"

```

This will then map the fields in the user’s properties (visible in Raw JSON view on user screen).

Then you can create a new rule which extracts from the samlp identity profile data into the user metadata.

```auto
function mapSamlAttributes(user, context, callback) {
  if(user.identities) {
    if(!user.user_metadata) {
      user.user_metadata = {};
    }
  	user.user_metadata.user_type = user.identities[1].profileData.user_type;
  	user.user_metadata.npi = user.identities[1].profileData.npi;
  }
  
  callback(null, user, context);
}

```

This can probably be improved by not hardcoding an index into the identities collection and instead looking for the exact identity you want.

---

<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:** [June 25, 2021, 7:17am UTC](https://community.auth0.com/t/how-to-map-extra-saml-attributes-from-idp-into-auth0-profile/64049/4 "2021-06-25T07:17:48Z")

</div>

Thanks for sharing it with the rest of community!

---

<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:** [July 10, 2021, 7:18am UTC](https://community.auth0.com/t/how-to-map-extra-saml-attributes-from-idp-into-auth0-profile/64049/5 "2021-07-10T07:18:11Z")

</div>

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