Hello - I am trying to use EventSub websockets to get channel follows in an extension front end. I can connect to the EventSub websocket just fine and I receive the welcome message, but when I try and subscribe to the event I get a 401 - “invalid JWT used”. I am using the helixToken that the extension onAuthorized function returns.
Twitch.ext.onAuthorized(function (auth) {
console.log(auth);
const socket = new WebSocket('wss://eventsub-beta.wss.twitch.tv/ws');
let websocket_id = null;
// Connection opened
socket.addEventListener('open', function (event) {
console.log("open", event);
});
// Listen for messages
socket.addEventListener('message', function (event) {
const data = JSON.parse(event.data);
console.log('Message from server ', data);
if (data.metadata.message_type === 'session_welcome') {
websocket_id = data.payload.session.id;
}
$.ajax({
url: 'https://api.twitch.tv/helix/eventsub/subscriptions',
type: 'POST',
headers: {
'Client-ID': 'auth.clientId',
'Authorization': 'Extension ' + auth.token, // Using token instead of helixToken for devrig.
'Content-Type': 'application/json'
},
data: JSON.stringify({
"type": "channel.follow",
"version": "1",
"condition": {
"broadcaster_user_id": auth.channelId
},
"transport": {
"method": "websocket",
"session_id": websocket_id
}
}),
success: function (data) {
console.log("success", data);
}
});
});
});
Should this be possible with the extension token, and if so what else might be the issue?
Thanks