feat: add migrations, api bot endpoints and revamp the whole twitch backend by making use of twitchio
This commit is contained in:
parent
8799bab900
commit
4c534de47b
45 changed files with 1718 additions and 1109 deletions
31
src/huesoporro/api/routes/auth.py
Normal file
31
src/huesoporro/api/routes/auth.py
Normal 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)}"
|
||||
},
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue