# WebSocket EventSub Token problem

**URL:** <https://discuss.dev.twitch.com/t/websocket-eventsub-token-problem/45760>\
**Category:** API\
**Created:** [May 14, 2023, 7:11pm UTC](https://discuss.dev.twitch.com/t/websocket-eventsub-token-problem/45760 "2023-05-14T19:11:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![AlexDD\_10](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/alexdd_10/32/24686_2.png) [@AlexDD\_10](https://discuss.dev.twitch.com/u/AlexDD_10)\
**Post date:** [May 14, 2023, 7:11pm UTC](https://discuss.dev.twitch.com/t/websocket-eventsub-token-problem/45760/1 "2023-05-14T19:11:20Z")

</div>

Hey, im trying to create a WebSocket where i would get the events that im trying to suscribe with EventSub, but when i try to subscribe, it throws me this error : **{"error":"Unauthorized","status":401,"message":"Invalid OAuth token"}**

```auto
        const headers = {
          'Client-ID': clientId,
          'Authorization': `Bearer ${accessToken}`,
        };
        const data = {
          "type": "stream.online",
          "version": "1",
          "condition": {
            "broadcaster_user_id": "134112649"
          },
          "transport": {  
            "method": "websocket",
            "session_id": `${id}`
          }
        };

          const response = await axios.post(`https://api.twitch.tv/helix/eventsub/subscriptions`, data,{headers});

```

Right now im sending the Client Secret (of the app) and it throws the error i said before, but if i try to send the token that returns the next code it just says it’s not the correct token with the method websockets

` const response = await axios.post(`[https://id.twitch.tv/oauth2/token?client\_id=${clientId}&client\_secret=${accessToken}&grant\_type=client\_credentials`](https://id.twitch.tv/oauth2/token?client_id=%24%7BclientId%7D&client_secret=%24%7BaccessToken%7D&grant_type=client_credentials%60));

`

I saw that websocket works with user access token, so i would have to ask to the user if it gives authorization, but i dont want that (i have been 2 days with this im so lost at this point)

---

<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:** [May 14, 2023, 7:13pm UTC](https://discuss.dev.twitch.com/t/websocket-eventsub-token-problem/45760/2 "2023-05-14T19:13:06Z")

</div>

> [@AlexDD\_10](#):
>
> Right now im sending the Client Secret (of the app)

The client secret is a secret it is not a token.

> [@AlexDD\_10](#):
>
> I saw that websocket works with user access token, so i would have to ask to the user if it gives authorization, but i dont want that (i have been 2 days with this im so lost at this point)

Websocket Eventsub _only_ supports User Access tokens.

if you are a server solution - EventSub Webhooks (uses app access)  
if you are a client side solution - EventSub websockets (users user access)

---

<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:** [June 13, 2023, 7:13pm UTC](https://discuss.dev.twitch.com/t/websocket-eventsub-token-problem/45760/3 "2023-06-13T19:13:25Z")

</div>

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