From 3ce36f0987cb8bb92afc5447defc70b46a02ea50 Mon Sep 17 00:00:00 2001 From: Bulat Kurbanov Date: Tue, 19 Nov 2024 17:38:19 +0100 Subject: [PATCH] Update twitch oauth --- .github/workflows/build_docker_image.yml | 6 ++++++ src/modules/web_app/views/auth.py | 22 +++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build_docker_image.yml b/.github/workflows/build_docker_image.yml index 98e9e87..a8ffdfd 100644 --- a/.github/workflows/build_docker_image.yml +++ b/.github/workflows/build_docker_image.yml @@ -66,3 +66,9 @@ jobs: uses: joelwmale/webhook-action@master with: url: ${{ secrets.WEBHOOK_URL_4 }} + + - + name: Invoke deployment hook (web_app) + uses: joelwmale/webhook-action@master + with: + url: ${{ secrets.WEBHOOK_URL_5 }} diff --git a/src/modules/web_app/views/auth.py b/src/modules/web_app/views/auth.py index db99143..c432b6c 100644 --- a/src/modules/web_app/views/auth.py +++ b/src/modules/web_app/views/auth.py @@ -1,5 +1,7 @@ from fastapi import APIRouter +from twitchAPI.twitch import Twitch, AuthScope +from twitchAPI.helper import first from httpx_oauth.oauth2 import OAuth2 from core.config import config @@ -8,7 +10,25 @@ from core.config import config auth_router = APIRouter(prefix="/auth", tags=["auth"]) -twitch_oauth = OAuth2( +class TwithOAuth2(OAuth2): + async def get_id_email(self, token: str): + twitch_client = Twitch(config.TWITCH_CLIENT_ID, config.TWITCH_CLIENT_SECRET) + + await twitch_client.set_user_authentication( + token, + [AuthScope.USER_READ_EMAIL], + validate=True + ) + + me = await first(twitch_client.get_users()) + + if me is None: + raise Exception("Failed to get user data") + + return me.id, me.email + + +twitch_oauth = TwithOAuth2( config.TWITCH_CLIENT_ID, config.TWITCH_CLIENT_SECRET, "https://id.twitch.tv/oauth2/authorize",