feat: add migrations, api bot endpoints and revamp the whole twitch backend by making use of twitchio

This commit is contained in:
cătălin 2024-12-17 17:55:02 +01:00
commit 4c534de47b
No known key found for this signature in database
45 changed files with 1718 additions and 1109 deletions

View file

@ -0,0 +1,31 @@
import secrets
from litestar import MediaType, get
from litestar.response import Redirect, Template
from src.huesoporro.settings import Settings
from src.huesoporro.svc.authenticate import CodeAuthenticatorSvc
@get(path="/o/code")
async def get_code(code: str, code_authenticator_svc: CodeAuthenticatorSvc) -> Redirect:
user = await code_authenticator_svc.run(code)
return Redirect("/", cookies={"huesoporroAuth": user.encode()})
@get(
"/login",
media_type=MediaType.HTML,
)
async def login(s: Settings) -> Template:
scopes = "+".join(s.twitch_scopes)
return Template(
"login.html",
context={
"twitch_login_url": "https://id.twitch.tv/oauth2/authorize?response_type=code"
f"&client_id={s.twitch_client_id}"
f"&redirect_uri={s.server_hostname}o/code"
f"&scope={scopes}"
f"&state={secrets.token_urlsafe(32)}"
},
)