# Profile from Apple is not fully normalized

**URL:** <https://community.auth0.com/t/profile-from-apple-is-not-fully-normalized/39153>\
**Category:** Get Help\
**Created:** [March 10, 2020, 10:30pm UTC](https://community.auth0.com/t/profile-from-apple-is-not-fully-normalized/39153 "2020-03-10T22:30:59Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mikhailk](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/mikhailk/32/13181_2.png) [@mikhailk](https://community.auth0.com/u/mikhailk)\
**Post date:** [March 10, 2020, 10:31pm UTC](https://community.auth0.com/t/profile-from-apple-is-not-fully-normalized/39153/1 "2020-03-10T22:31:00Z")

</div>

Hello,

I’m using Apple social connection to login. I can see the user created. The user has field “last\_name”, but no field “family\_name”. Isn’t the field “family\_name” mandatory on normalized profile?  
See the screen shot attached

 ![Screen Shot 2020-03-11 at 11.17.17 AM](https://global.discourse-cdn.com/auth0/original/3X/3/8/38c825d41fc54e35eb5d44738cb7830799855d24.png)

---

<div class="post-metadata">

**Author:** ![mikhailk](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/mikhailk/32/13181_2.png) [@mikhailk](https://community.auth0.com/u/mikhailk)\
**Post date:** [March 11, 2020, 8:30am UTC](https://community.auth0.com/t/profile-from-apple-is-not-fully-normalized/39153/2 "2020-03-11T08:30:23Z")

</div>

Another example, see screenshot attached. Apple sends “first\_name” and “last\_name”, but profile has no “given\_name” nor “family\_name”

 ![Screen Shot 2020-03-11 at 9.23.36 PM](https://global.discourse-cdn.com/auth0/original/3X/8/4/84fdba9b6d86921d330e0bda5b7a1ad28ae680d8.png)

---

<div class="post-metadata">

**Author:** ![mathiasconradt](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/mathiasconradt/32/12758_2.png) [@mathiasconradt](https://community.auth0.com/u/mathiasconradt)\
**Post date:** [March 11, 2020, 8:47am UTC](https://community.auth0.com/t/profile-from-apple-is-not-fully-normalized/39153/3 "2020-03-11T08:47:42Z")

</div>

I believe (haven’t checked myself), the claims `first_name` and `last_name` come like this from Apple, despite `family_name` and \_given\_name` being the [OIDC standard claims](https://openid.net/specs/openid-connect-core-1_0.html#StandardClaims).

If you need to map this though, you can do it within a Rule (tbh - I don’t know why it’s not automatically mapped by the Apple ID social connection by default due to normalization).  
So, as a workaround, this rule should work:

```auto
function (user, context, callback) {

  // you might want to add a check to only run this 
  // if `user.family_name` and `user.given_name` is actually missing
  if (context.connectionStrategy === "apple") { 

    var ManagementClient = require('auth0@2.6.0').ManagementClient;
    var management = new ManagementClient({
        token: auth0.accessToken,
        domain: auth0.domain
    });
        
     // persist in user store
    management.updateUser({id: user.user_id}, 
        {family_name: user.last_name, given_name: user.first_name})
    .then(function(u){    
      callback(null, u, context);
    })
    .catch(function(err){
      callback(err);
    });     
  } else { // if not apple
    callback(null, user, context);
  }

```

}

---

<div class="post-metadata">

**Author:** ![Pocket7878](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/pocket7878/32/27719_2.png) [@Pocket7878](https://community.auth0.com/u/Pocket7878)\
**Post date:** [February 19, 2021, 5:57pm UTC](https://community.auth0.com/t/profile-from-apple-is-not-fully-normalized/39153/4 "2021-02-19T17:57:41Z")

</div>

I’ve tried mathiasconradt’s recommendation but unfortunately it doesn’t work me cause from Auth0 forbid to update family\_name, given\_name fields for apple connection user without disabling “Sync user profile attributes at each login” option and it gave me an error:

> The following user attributes cannot be updated: family\_name, given\_name. The connection (apple) must either be a database connection (using the Auth0 store), a passwordless connection (email or sms) or has disabled 'Sync user profile attributes at each login'. For more information, see [Configure Identity Provider Connection for User Profile Updates](https://auth0.com/docs/dashboard/guides/connections/configure-connection-sync)

So, I’ve stored `last_name` and `first_name` into `user_metadata` field:

```auto
function (user, context, callback) {

  // you might want to add a check to only run this 
  // if `user.family_name` and `user.given_name` is actually missing
  if (context.connectionStrategy === "apple") { 

    var ManagementClient = require('auth0@2.32.0').ManagementClient;
    var management = new ManagementClient({
        token: auth0.accessToken,
        domain: auth0.domain
    });
        
     // persist in user store
    management.updateUser({id: user.user_id}, 
        {user_metadata: { apple_family_name: user.last_name, apple_given_name: user.first_name }})
    .then(function(u){    
      callback(null, u, context);
    })
    .catch(function(err){
      callback(err);
    });     
  } else { // if not apple
    callback(null, user, context);
  }

}

```

and reading with fallback in server (in Ruby):

```ruby
user_profile = auth0_client.user(
  auth0_subject,
  fields: "family_name,given_name,user_metadata"
)
family_name = user_profile["family_name"] || user_profile.dig("user_metadata", "apple_family_name")
given_name = user_profile["given_name"] || user_profile.dig("user_metadata", "apple_given_name")

```

---

<div class="post-metadata">

**Author:** ![nicolas\_sabena](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/nicolas_sabena/32/6064_2.png) [@nicolas\_sabena](https://community.auth0.com/u/nicolas_sabena)\
**Post date:** [September 1, 2021, 9:43pm UTC](https://community.auth0.com/t/profile-from-apple-is-not-fully-normalized/39153/5 "2021-09-01T21:43:40Z")

</div>

A simpler solution that doesn’t involve using the Management API would be:

```auto
function(user, context, callback) {
  if (context.connectionStrategy === "apple") { 
    user.family_name = user.family_name || user.last_name;
    user.given_name = user.given_name || first_name;
  }
  callback(null, user, context);
}

```

This won’t cause any permanent changes in the user profile (it’s just a transient change for the ongoing authentication flow), but it affects the outgoing token being generated by Auth0 (be it an ID Token or a SAML token).  
By not using the Management API v2 on every login you ensure better response times, and you stay away from any rate limiting (the Management API v2 has much lower rate limits than the Authentication API, so it’s not a good idea to have a rule that calls the Management API v2 every single time the rule runs).

---

<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:** [September 2, 2021, 11:16am UTC](https://community.auth0.com/t/profile-from-apple-is-not-fully-normalized/39153/6 "2021-09-02T11:16:50Z")

</div>

Thanks for helping on this one Nico!

---

<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:** [September 17, 2021, 11:17am UTC](https://community.auth0.com/t/profile-from-apple-is-not-fully-normalized/39153/7 "2021-09-17T11:17:01Z")

</div>

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