Twitch Integration Missing Twitch Username

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.

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, therefore you will need to map username to a custom claim via a post-login Action

E.g.

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.

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 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:

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.

3 Likes

Just a small correction to the solution.

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

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

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

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

2 Likes

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