Skip to content

Commit 69e95e9

Browse files
authored
Add SSLContext arg to aiohttp adapter (#483)
* Add SSLContext arg to aiohttp adapter Pass an SSLContext to the aiohttp adapter to create a valid SSL endpoint for OAuth callback. * Update docs for aiohttp adapter * Added ssl import to pass linter checks * Moved import to TYPE_CHECKING Moved the ssl import to TYPE_CHECKING section. * Removed trailing whitespace * Fix import format issue from Ruff
1 parent 4a59b7c commit 69e95e9

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

twitchio/web/aio_adapter.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343

4444

4545
if TYPE_CHECKING:
46+
from ssl import SSLContext
47+
4648
from ..authentication import AuthorizationURLPayload, UserTokenPayload
4749
from ..client import Client
4850

@@ -101,6 +103,8 @@ class AiohttpAdapter(BaseAdapter, web.Application):
101103
An optional :class:`str` passed to use as the EventSub secret. It is recommended you pass this parameter when using
102104
an adapter for EventSub, as it will reset upon restarting otherwise. You can generate token safe secrets with the
103105
:mod:`secrets` module.
106+
ssl_context: SSLContext | None
107+
An optional :class:`SSLContext` passed to the adapter. If SSL is setup via a front-facing web server such as NGINX, you should leave this as None.
104108
105109
Examples
106110
--------
@@ -139,6 +143,7 @@ def __init__(
139143
domain: str | None = None,
140144
eventsub_path: str | None = None,
141145
eventsub_secret: str | None = None,
146+
ssl_context: SSLContext | None = None,
142147
) -> None:
143148
super().__init__()
144149
self._runner: web.AppRunner | None = None
@@ -160,6 +165,8 @@ def __init__(
160165
path: str = eventsub_path.removeprefix("/").removesuffix("/") if eventsub_path else "callback"
161166
self._eventsub_path: str = f"/{path}"
162167

168+
self._ssl_context: SSLContext | None = ssl_context
169+
163170
self._runner_task: asyncio.Task[None] | None = None
164171
self.startup = self.event_startup
165172
self.shutdown = self.event_shutdown
@@ -210,7 +217,7 @@ async def run(self, host: str | None = None, port: int | None = None) -> None:
210217
self._runner = web.AppRunner(self, access_log=None, handle_signals=True)
211218
await self._runner.setup()
212219

213-
site: web.TCPSite = web.TCPSite(self._runner, host or self._host, port or self._port)
220+
site: web.TCPSite = web.TCPSite(self._runner, host or self._host, port or self._port, ssl_context=self._ssl_context)
214221
self._runner_task = asyncio.create_task(site.start(), name=f"twitchio-web-adapter:{self.__class__.__qualname__}")
215222

216223
async def eventsub_callback(self, request: web.Request) -> web.Response:

0 commit comments

Comments
 (0)