auth.userId shows opaque even though authorized


#1

Hello, I am working on an extension and have it hosted on my web server. I’ve enabled it on my channel and when I stream I am able to get it to show and behave as expected so far except that when I get the user_id by using

twitch.onAuthorized(function(auth) {
            token = auth.token;
            userId = auth.userId;
      });

I still receive an opaque user ID that starts with “U” even though it is authorized

I tried calling requestIdShare like this:

Twitch.ext.actions.requestIdShare((e) => {console.log(e)});

but it only pops up the permissions and shows me the ability to revoke the permissions.

I’ll add that under capabilities, I’ve turned on monetization, which grays out (and checks) the checkbox “Yes, I would like my extension to request an identity link.”


#2

That’s because auth.userID is always an opaque id, as per the documentation on what is returned by the onAuthorized() function https://dev.twitch.tv/docs/extensions/reference/#helper-extensions

To get the user id once you have requested the ID share like you have you need to decode the JWT and you’ll get an object as described by the JWT Schema in the docs https://dev.twitch.tv/docs/extensions/reference/#jwt-schema

It’s within that token you’ll find the user_id field which has their Twitch ID in it. For users who haven’t accepted the ID sharing this field will not be present.


#3

Thanks, works!