Implement the auth token invalidation button

This commit is contained in:
DevilXD committed 2026-07-02 15:19:53 +02:00
1 parent 98f166d94d
commit 38f880efc2
4 files changed
+66 -4

No files matched your search

+40 -1
View File
@@ -36,7 +36,7 @@ if sys.platform == "darwin":
from translate import _
from cache import ImageCache
from exceptions import MinerException, ExitRequest
from utils import resource_path, set_root_icon, webopen, Game, _T
from utils import resource_path, set_root_icon, webopen, task_wrapper, Game, _T
from constants import (
MAX_INT,
SELF_PATH,
@@ -61,6 +61,7 @@ if TYPE_CHECKING:
from inventory import DropsCampaign, TimedDrop
logger = logging.getLogger("TwitchDrops")
TK_PADDING = Union[int, Tuple[int, int], Tuple[int, int, int], Tuple[int, int, int, int]]
DIGITS = ceil(log10(WS_TOPICS_LIMIT))
@@ -2096,6 +2097,9 @@ class HelpTab:
# use a frame to center the content within the tab
center_frame = ttk.Frame(master)
center_frame.grid(column=0, row=0)
# use a frame for the bottom row specifically
bottom_frame = ttk.Frame(master)
bottom_frame.grid(column=0, row=1, sticky="nsew")
irow = 0
# About
about = ttk.LabelFrame(center_frame, padding=(4, 0, 4, 4), text="About")
@@ -2160,6 +2164,41 @@ class HelpTab:
getstarted, text=_("gui", "help", "getting_started_text"), wraplength=self.WIDTH
).grid(sticky="nsew")
# Invalidate button
invalidate_frame = ttk.Frame(bottom_frame)
bottom_frame.columnconfigure(0, weight=1) # center within the column
invalidate_frame.grid(column=0, row=0, sticky="nse")
ttk.Label(
invalidate_frame, text=_("gui", "help", "invalidate", "text")
).grid(column=0, row=0)
self._invalidate_button: ttk.Button = ttk.Button(
invalidate_frame,
text=_("gui", "help", "invalidate", "button"),
command=self.invalidate_token,
state="disabled",
)
self._invalidate_button.grid(column=1, row=0)
def invalidate_token(self) -> None:
# sync to async bridge
asyncio.create_task(task_wrapper(self._invalidate_token)())
async def _invalidate_token(self) -> None:
auth_state = await self._twitch.get_auth()
async with self._twitch.request(
"POST",
"https://id.twitch.tv/oauth2/revoke",
data={
"client_id": self._twitch._client_type.CLIENT_ID,
"token": auth_state.access_token,
}
) as response:
if response.status == 200:
auth_state.invalidate(delete_cookies=True)
else:
logger.error(f"Failed to invalidate the auth token: {response.status}")
self._twitch.change_state(State.RESTART)
##########################################
# GUI DEFINITION END / GUI MANAGER START #