Update twitch oauth

This commit is contained in:
2024-11-19 17:38:19 +01:00
parent 514ab5050a
commit 3ce36f0987
2 changed files with 27 additions and 1 deletions

View File

@@ -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 }}

View File

@@ -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",