Skip to content

Commit 64e5402

Browse files
committed
update eventsub to allow for a separate token
1 parent c3c1c93 commit 64e5402

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

twitchio/ext/eventsub/http.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from typing import TYPE_CHECKING, Tuple, Dict, Type, Union
1+
from __future__ import annotations
2+
from typing import TYPE_CHECKING, Tuple, Dict, Type, Union, Optional
23
from ...http import Route
34

45
from . import models
@@ -11,21 +12,22 @@
1112

1213

1314
class EventSubHTTP:
14-
def __init__(self, client: "EventSubClient"):
15+
def __init__(self, client: EventSubClient, token: Optional[str]):
1516
self._client = client
1617
self._http = client.client._http
18+
self._token = token or self._http.token
1719

18-
async def create_subscription(self, event_type: Tuple[str, int, Type["EventData"]], condition: Dict[str, str]):
20+
async def create_subscription(self, event_type: Tuple[str, int, Type[EventData]], condition: Dict[str, str]):
1921
payload = {
2022
"type": event_type[0],
2123
"version": str(event_type[1]),
2224
"condition": condition,
2325
"transport": {"method": "webhook", "callback": self._client.route, "secret": self._client.secret},
2426
}
25-
route = Route("POST", "eventsub/subscriptions", body=payload)
27+
route = Route("POST", "eventsub/subscriptions", body=payload, token=self._token)
2628
return await self._http.request(route, paginate=False)
2729

28-
async def delete_subscription(self, substription: Union[str, "Subscription"]):
30+
async def delete_subscription(self, substription: Union[str, Subscription]):
2931
if isinstance(substription, models.Subscription):
3032
return await self._http.request(
3133
Route("DELETE", "eventsub/subscriptions", query=[("id", substription.id)]), paginate=False

twitchio/ext/eventsub/server.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@
2727

2828

2929
class EventSubClient(web.Application):
30-
def __init__(self, client: Client, webhook_secret: str, callback_route: str):
30+
def __init__(self, client: Client, webhook_secret: str, callback_route: str, token: str = None):
3131
self.client = client
3232
self.secret = webhook_secret
3333
self.route = callback_route
34-
self._http = http.EventSubHTTP(self)
34+
self._http = http.EventSubHTTP(self, token=token)
3535
super(EventSubClient, self).__init__()
3636
self.router.add_post(yarl.URL(self.route).path, self._callback)
3737
self._closing = asyncio.Event()

0 commit comments

Comments
 (0)