Skip to content

Commit 557443d

Browse files
committed
Add oauth_path optional parameter.
1 parent 2267da8 commit 557443d

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

twitchio/web/aio_adapter.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ class AiohttpAdapter(BaseAdapter, web.Application):
105105
An optional :class:`str` passed to use as the EventSub secret. It is recommended you pass this parameter when using
106106
an adapter for EventSub, as it will reset upon restarting otherwise. You can generate token safe secrets with the
107107
:mod:`secrets` module.
108+
oauth_path: str | None
109+
An optional :class:`str` passed to use as the path for the OAuth route. Defaults to ``/oauth``.
110+
E.g. ``http://localhost:4343/oauth`` or ``https://mydomain.org/oauth``.
108111
redirect_path: str | None
109112
An optional :class:`str` passed to use as the path for the Oauth Redirect callback. Defaults to ``/oauth/callback``.
110113
E.g. ``http://localhost:4343/oauth/callback`` or ``https://mydomain.org/oauth/callback``.
@@ -148,6 +151,7 @@ def __init__(
148151
domain: str | None = None,
149152
eventsub_path: str | None = None,
150153
eventsub_secret: str | None = None,
154+
oauth_path: str | None = None,
151155
redirect_path: str | None = None,
152156
ssl_context: SSLContext | None = None,
153157
) -> None:
@@ -173,15 +177,18 @@ def __init__(
173177
path: str = eventsub_path.removeprefix("/").removesuffix("/") if eventsub_path else "callback"
174178
self._eventsub_path: str = f"/{path}"
175179

176-
opath: str = redirect_path.removeprefix("/").removesuffix("/") if redirect_path else "oauth/callback"
177-
self._redirect_path: str = f"/{opath}"
180+
rpath: str = redirect_path.removeprefix("/").removesuffix("/") if redirect_path else "oauth/callback"
181+
self._redirect_path: str = f"/{rpath}"
182+
183+
opath: str = oauth_path.removeprefix("/").removesuffix("/") if oauth_path else "oauth"
184+
self._oauth_path: str = f"/{opath}"
178185

179186
self._runner_task: asyncio.Task[None] | None = None
180187
self.startup = self.event_startup
181188
self.shutdown = self.event_shutdown
182189

183190
self.router.add_route("GET", self._redirect_path, self.oauth_callback)
184-
self.router.add_route("GET", "/oauth", self.oauth_redirect)
191+
self.router.add_route("GET", self._oauth_path, self.oauth_redirect)
185192
self.router.add_route("POST", self._eventsub_path, self.eventsub_callback)
186193

187194
self._responded: deque[str] = deque(maxlen=5000)

twitchio/web/starlette_adapter.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ class StarletteAdapter(BaseAdapter, Starlette):
107107
An optional :class:`str` passed to use as the EventSub secret. It is recommended you pass this parameter when using
108108
an adapter for EventSub, as it will reset upon restarting otherwise. You can generate token safe secrets with the
109109
:mod:`secrets` module.
110+
oauth_path: str | None
111+
An optional :class:`str` passed to use as the path for the OAuth route. Defaults to ``/oauth``.
112+
E.g. ``http://localhost:4343/oauth`` or ``https://mydomain.org/oauth``.
110113
redirect_path: str | None
111114
An optional :class:`str` passed to use as the path for the Oauth Redirect callback. Defaults to ``/oauth/callback``.
112115
E.g. ``http://localhost:4343/oauth/callback`` or ``https://mydomain.org/oauth/callback``.
@@ -160,6 +163,7 @@ def __init__(
160163
domain: str | None = None,
161164
eventsub_path: str | None = None,
162165
eventsub_secret: str | None = None,
166+
oauth_path: str | None = None,
163167
redirect_path: str | None = None,
164168
ssl_keyfile: str | PathLike[str] | None = None,
165169
ssl_keyfile_password: str | None = None,
@@ -188,16 +192,19 @@ def __init__(
188192
path: str = eventsub_path.removeprefix("/").removesuffix("/") if eventsub_path else "callback"
189193
self._eventsub_path: str = f"/{path}"
190194

191-
opath: str = redirect_path.removeprefix("/").removesuffix("/") if redirect_path else "oauth/callback"
192-
self._redirect_path: str = f"/{opath}"
195+
rpath: str = redirect_path.removeprefix("/").removesuffix("/") if redirect_path else "oauth/callback"
196+
self._redirect_path: str = f"/{rpath}"
197+
198+
opath: str = oauth_path.removeprefix("/").removesuffix("/") if oauth_path else "oauth"
199+
self._oauth_path: str = f"/{opath}"
193200

194201
self._runner_task: asyncio.Task[None] | None = None
195202
self._responded: deque[str] = deque(maxlen=5000)
196203

197204
super().__init__(
198205
routes=[
199206
Route(self._redirect_path, self.oauth_callback, methods=["GET"]),
200-
Route("/oauth", self.oauth_redirect, methods=["GET"]),
207+
Route(self._oauth_path, self.oauth_redirect, methods=["GET"]),
201208
Route(self._eventsub_path, self.eventsub_callback, methods=["POST"]),
202209
],
203210
on_shutdown=[self.event_shutdown],

0 commit comments

Comments
 (0)