fix: retrieve user profile after refreshing twitch creds

This commit is contained in:
cătălin 2025-02-24 11:29:12 +01:00
commit 1452f2076b
No known key found for this signature in database
7 changed files with 18 additions and 16 deletions

View file

@ -15,10 +15,10 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.2.7
version: 0.2.8
# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "0.2.7"
appVersion: "0.2.8"

View file

@ -11,7 +11,7 @@ image:
# This sets the pull policy for images.
pullPolicy: Always
# Overrides the image tag whose default is the chart appVersion.
tag: "0.2.7"
tag: "0.2.8"
# This is for the secretes for pulling an image from a private repository more information can be found here: https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/
imagePullSecrets: []

View file

@ -10,6 +10,7 @@
languages.python.version = "3.12.8";
enterShell = ''
uv sync
'';
dotenv.enable = true;

View file

@ -1,6 +1,6 @@
[project]
name = "huesoporro"
version = "0.2.5"
version = "0.2.8"
description = "Misc Twitch bots"
readme = "README.md"
authors = [

View file

@ -11,17 +11,17 @@ class RefreshAction(BaseModel):
authenticator: TwitchAuthenticator
s: Settings
async def run(self, user: User):
async def run(self, user: User) -> str | None:
is_valid = await self.authenticator.token_is_valid(
user.external_auth["twitch"]["access_token"]
)
if is_valid:
return None
if not is_valid:
new_tokens = await self.authenticator.refresh_token(
user.external_auth["twitch"]["refresh_token"]
)
user.external_auth["twitch"]["access_token"] = new_tokens["access_token"] # type: ignore[index]
user.external_auth["twitch"]["refresh_token"] = new_tokens["refresh_token"] # type: ignore[index]
await self.user_repo.update(user)
return user.encode()
return None
twitch_auth = await self.authenticator.refresh_token(
user.external_auth["twitch"]["refresh_token"]
)
user.external_auth["twitch"]["access_token"] = twitch_auth.access_token
user.external_auth["twitch"]["refresh_token"] = twitch_auth.refresh_token
await self.user_repo.update(user)
return user.encode()

View file

@ -52,7 +52,8 @@ class TwitchAuthenticator(BaseModel):
headers={"Accept": "application/json"},
)
response.raise_for_status()
return TwitchAuth(**response.json())
profile = await self.get_userinfo(response.json()["access_token"])
return TwitchAuth(**response.json(), userinfo=profile)
async def validate_token(self, access_token: str) -> str:
response = await self.client.get(

2
uv.lock generated
View file

@ -472,7 +472,7 @@ wheels = [
[[package]]
name = "huesoporro"
version = "0.2.5"
version = "0.2.8"
source = { virtual = "." }
dependencies = [
{ name = "aiosqlite" },