Skip to content

Commit d25fe42

Browse files
committed
Fix redirect URIs issue
Closes #33.
1 parent 00d7182 commit d25fe42

4 files changed

Lines changed: 33 additions & 1 deletion

File tree

analytix/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
)
3939

4040
__productname__ = "analytix"
41-
__version__ = "3.3.1"
41+
__version__ = "3.3.2"
4242
__description__ = "A simple yet powerful wrapper for the YouTube Analytics API."
4343
__url__ = "https://github.com/parafoxia/analytix"
4444
__docs__ = "https://analytix.readthedocs.io"

analytix/analytics.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import os
3434
import pathlib
3535
import typing as t
36+
from warnings import warn
3637

3738
import httpx
3839

@@ -205,6 +206,12 @@ def authorise( # nosec B107
205206
The tokens the client is authorised with.
206207
"""
207208

209+
warning = (
210+
"Code-based authorisation is deprecated due to a breaking change in the "
211+
"Google APIs -- analytix is patching your secrets file where necessary for "
212+
"now, but the authorisation method will change in the next version"
213+
)
214+
208215
if not isinstance(token_path, pathlib.Path):
209216
token_path = pathlib.Path(token_path)
210217

@@ -220,6 +227,11 @@ def authorise( # nosec B107
220227
if not self._tokens:
221228
log.info("Unable to load tokens; you will need to authorise")
222229
self._tokens = self._retrieve_tokens()
230+
# Temporary warning regarding authorisation methods.
231+
if log.hasHandlers() and log.getEffectiveLevel() <= 30:
232+
log.warning(warning)
233+
else:
234+
warn(warning)
223235
self._tokens.write(token_path)
224236

225237
log.info("Authorisation complete!")

analytix/async_analytics.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import os
3434
import pathlib
3535
import typing as t
36+
from warnings import warn
3637

3738
import httpx
3839

@@ -208,6 +209,12 @@ async def authorise( # nosec B107
208209
The tokens the client is authorised with.
209210
"""
210211

212+
warning = (
213+
"Code-based authorisation is deprecated due to a breaking change in the "
214+
"Google APIs -- analytix is patching your secrets file where necessary for "
215+
"now, but the authorisation method will change in the next version"
216+
)
217+
211218
if not isinstance(token_path, pathlib.Path):
212219
token_path = pathlib.Path(token_path)
213220

@@ -223,6 +230,11 @@ async def authorise( # nosec B107
223230
if not self._tokens:
224231
log.info("Unable to load tokens; you will need to authorise")
225232
self._tokens = await self._retrieve_tokens()
233+
# Temporary warning regarding authorisation methods.
234+
if log.hasHandlers() and log.getEffectiveLevel() <= 30:
235+
log.warning(warning)
236+
else:
237+
warn(warning)
226238
await self._tokens.awrite(token_path)
227239

228240
log.info("Authorisation complete!")

analytix/secrets.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ def from_file(cls, path: pathlib.Path | str) -> Secrets:
103103
with open(path) as f:
104104
data = json.load(f)["installed"]
105105

106+
# Temporary patch to account for the breaking change in the API.
107+
if "urn:ietf:wg:oauth:2.0:oob" not in data["redirect_uris"]:
108+
data["redirect_uris"].insert(0, "urn:ietf:wg:oauth:2.0:oob")
109+
106110
log.info("Secrets loaded!")
107111
return cls(**data)
108112

@@ -127,6 +131,10 @@ async def afrom_file(cls, path: pathlib.Path | str) -> Secrets:
127131
async with aiofiles.open(path) as f:
128132
data = json.loads(await f.read())["installed"]
129133

134+
# Temporary patch to account for the breaking change in the API.
135+
if "urn:ietf:wg:oauth:2.0:oob" not in data["redirect_uris"]:
136+
data["redirect_uris"].insert(0, "urn:ietf:wg:oauth:2.0:oob")
137+
130138
log.info("Secrets loaded!")
131139
return cls(**data)
132140

0 commit comments

Comments
 (0)