# Twitch Integration Missing Twitch Username

**URL:** <https://community.auth0.com/t/twitch-integration-missing-twitch-username/79100>\
**Category:** Integration Help\
**Created:** [March 2, 2022, 1:12am UTC](https://community.auth0.com/t/twitch-integration-missing-twitch-username/79100 "2022-03-02T01:12:20Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![DaftPenguin](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/daftpenguin/32/33194_2.png) [@DaftPenguin](https://community.auth0.com/u/DaftPenguin)\
**Post date:** [March 2, 2022, 1:12am UTC](https://community.auth0.com/t/twitch-integration-missing-twitch-username/79100/1 "2022-03-02T01:12:20Z")

</div>

Since Twitch API v5 was decommissioned yesterday, I attempted to update my twitch connection but it seems the nickname in the user object is now filled in with the username part of their email address, rather than their twitch username. Their name is also now their email. Was this an intended change? Is there anyway to retrieve their username? This breaks a lot of things for my application as I was using auth0 as a means to verify the user had ownership of their twitch account.

---

<div class="post-metadata">

**Author:** ![sgo](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/sgo/32/13789_2.png) [@sgo](https://community.auth0.com/u/sgo)\
**Post date:** [March 2, 2022, 4:30pm UTC](https://community.auth0.com/t/twitch-integration-missing-twitch-username/79100/3 "2022-03-02T16:30:12Z")

</div>

Hi @DaftPenguin , welcome to the community!

In my testing, the Twitch username was stored under `username` in the generated Auth0 profile, but unfortunately `username` isn’t in the standard OIDC [claims](https://openid.net/specs/openid-connect-core-1_0.html#StandardClaims), therefore you will need to map `username` to a custom claim via a [post-login Action](https://auth0.com/docs/customize/actions/flows-and-triggers/login-flow)

E.g.

```auto
exports.onExecutePostLogin = async (event, api) => {

if (event.user.username) {
  const namespace = 'https://my-app.example.com';
  api.idToken.setCustomClaim(`${namespace}/username`, event.user.username)
}

};

```

This will then show the Twitch username in ID Tokens as your [custom namespaced claim](https://auth0.com/docs/secure/tokens/json-web-tokens/create-namespaced-custom-claims).

Currently Actions do not allow for editing the root user object in situ, so a custom claim is needed in this scenario as shown above.

If however Actions were changed such that you could edit the root profile like [Rules](https://auth0.com/docs/customize/rules) currently can ( I do not know if this is something that is planned or not currently), then you could map the `username` to `preferred_username` on the User’s root profile; something similar to what can be done in this **Rule** example:

```auto
function (user, context, callback) {
   if (user.username) {
      user.preferred_username = user.username;
   }
   return callback(null, user, context);
}

```

This way the `preferred_username` claim would be returned in ID Tokens without needing a custom namespace, as it is part of the OIDC spec and returned for a `profile` scope by default.

But as Rules are being deprecated eventually, I would recommend sticking with Actions to avoid needing extra migration work in the future.

---

<div class="post-metadata">

**Author:** ![opti21](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/opti21/32/35329_2.png) [@opti21](https://community.auth0.com/u/opti21)\
**Post date:** [March 17, 2022, 6:04am UTC](https://community.auth0.com/t/twitch-integration-missing-twitch-username/79100/4 "2022-03-17T06:04:06Z")

</div>

Just a small correction to the solution.

Make sure you return the callback otherwise the rule will never execute

```auto
function (user, context, callback) {
    if (user.username) {
      user.preferred_username = user.username;
   }
  return 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:** [March 17, 2022, 1:08pm UTC](https://community.auth0.com/t/twitch-integration-missing-twitch-username/79100/5 "2022-03-17T13:08:51Z")

</div>

Thanks for sharing that with the rest of community @opti21 !

---

<div class="post-metadata">

**Author:** ![sgo](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/sgo/32/13789_2.png) [@sgo](https://community.auth0.com/u/sgo)\
**Post date:** [March 17, 2022, 3:33pm UTC](https://community.auth0.com/t/twitch-integration-missing-twitch-username/79100/6 "2022-03-17T15:33:17Z")

</div>

Whoops, thanks @opti21 - I’ve edited my post to fix that oversight of mine

---

<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:** [April 1, 2022, 3:33pm UTC](https://community.auth0.com/t/twitch-integration-missing-twitch-username/79100/7 "2022-04-01T15:33:56Z")

</div>

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