# Issue with pubsub authentication

**URL:** <https://discuss.dev.twitch.com/t/issue-with-pubsub-authentication/19804>\
**Category:** API\
**Created:** [January 31, 2019, 4:39am UTC](https://discuss.dev.twitch.com/t/issue-with-pubsub-authentication/19804 "2019-01-31T04:39:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mobilehobo](https://avatars.discourse-cdn.com/v4/letter/m/e99b99/32.png) [@mobilehobo](https://discuss.dev.twitch.com/u/mobilehobo)\
**Post date:** [January 31, 2019, 4:39am UTC](https://discuss.dev.twitch.com/t/issue-with-pubsub-authentication/19804/1 "2019-01-31T04:39:42Z")

</div>

Hi all,

I’ve been working on a custom layout for twitch, and wanted to use PubSub for getting bits and subscriber notifications. I was using [socket.io](http://socket.io) for the connection but didn’t seem to connect at all, so I switched to the native WebSocket library. I was able to connect with that, but am getting a ‘ERR\_BADAUTH’ when trying to subscribe to the subscriber topic. I know the token I’m passing is good since I’m using the same for my website, and I am omitting the ‘oauth:’ portion too.

```
twitchSocket.onopen = (event) => {
      console.info('socket connected!');
      intervalId = setInterval(this.socketHeartbeat, 2 * 60 * 1000);

      twitchSocket.send(JSON.stringify({
        type: 'LISTEN',
        data: {
          topics: ['channel-subscribe-events-v1.MyUserID', 'channel-bits-events-v1.MyUserID'],
          auth_token: 'abc123', // changed for security
        },
      }) );
    };

```

That’s my connect code if it helps. I was able to connect fine without the subscriber event as well.

---

<div class="post-metadata">

**Author:** ![milo](https://avatars.discourse-cdn.com/v4/letter/m/85e7bf/32.png) [@milo](https://discuss.dev.twitch.com/u/milo)\
**Post date:** [January 31, 2019, 7:10am UTC](https://discuss.dev.twitch.com/t/issue-with-pubsub-authentication/19804/2 "2019-01-31T07:10:52Z")

</div>

> [@mobilehobo](#):
>
> I was able to connect fine without the subscriber event as well.

Are you sure your token has the `channel_subscriptions` scope which is required for the `channel-subscribe-events` topic?

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [January 31, 2019, 9:23am UTC](https://discuss.dev.twitch.com/t/issue-with-pubsub-authentication/19804/3 "2019-01-31T09:23:13Z")

</div>

As per the docs

> **[PubSub](https://dev.twitch.tv/docs/pubsub/#subscribing-to-topics)**
>
> PubSub Guide

You need to make sure that the auth key you are using has any scope for the bit’s topic, and a key with `channel_subscriptions` scope on it as @milo says

ERR\_BADAUTH means your key is invalid for one or more topics your requests to listen on in the same listen send.

---

<div class="post-metadata">

**Author:** ![mobilehobo](https://avatars.discourse-cdn.com/v4/letter/m/e99b99/32.png) [@mobilehobo](https://discuss.dev.twitch.com/u/mobilehobo)\
**Post date:** [February 1, 2019, 12:08am UTC](https://discuss.dev.twitch.com/t/issue-with-pubsub-authentication/19804/4 "2019-02-01T00:08:12Z")

</div>

I did add the channel\_subscriptions scope, and remember the oauth saying it too. It shouldn’t matter if I also have channel\_editor scope on the token right?

---

<div class="post-metadata">

**Author:** ![system](https://d2opxh93rbxzdn.cloudfront.net/original/2X/0/05909729875cce3b53e59d5561c4d23bb14948fc.png) [@system](https://discuss.dev.twitch.com/u/system)\
**Post date:** [March 3, 2019, 12:08am UTC](https://discuss.dev.twitch.com/t/issue-with-pubsub-authentication/19804/5 "2019-03-03T00:08:15Z")

</div>

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