First the extension has to have selected the option to request identity link in the Extension Capabilities section.
Then you can either use the requestIdShare helper function as mentioned in the docs https://dev.twitch.tv/docs/extensions/reference/#helper-actions or the user can click the permissions button for the extension (which is the bottom right of the panel for panel extensions, or for video extensions it can be found through the extensions icon at the bottom of the stream player).
Only once the user has agreed to share their identity (which they can later revoke if they choose to no longer share their ID with your extension) will the JWT include the user_id.