From 09542ab7b3776a7837408abf1b3a1b6aa6bbfe98 Mon Sep 17 00:00:00 2001 From: nex Date: Mon, 26 Feb 2024 13:21:21 +0000 Subject: [PATCH] Fix server --- web/server.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/web/server.py b/web/server.py index f738ad9..cffb9d2 100644 --- a/web/server.py +++ b/web/server.py @@ -14,15 +14,14 @@ from discord.ext.commands import Paginator import discord import httpx -from fastapi import FastAPI, Header, HTTPException, Request, dependencies, status, Depends +from fastapi import FastAPI, HTTPException, Request, status, Depends, Query from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials as HTTPAuthCreds from fastapi import WebSocketException as _WSException from fastapi.responses import HTMLResponse, JSONResponse, RedirectResponse from starlette.websockets import WebSocket, WebSocketDisconnect from websockets.exceptions import WebSocketException -from config import guilds -from utils import BannedStudentID, Student, VerifyCode, console, get_or_none, BridgeBind +from utils import get_or_none, BridgeBind from utils.db import AccessTokens SF_ROOT = Path(__file__).parent / "static" @@ -323,8 +322,8 @@ async def bridge_bind_new(mx_id: str): token = secrets.token_urlsafe() app.state.binds[token] = mx_id url = discord.utils.oauth_url( - OAUTH_ID, - redirect_uri=BIND_REDIRECT_URI, + OAUTH_ID, + redirect_uri=BIND_REDIRECT_URI, scopes=("identify",) ) + f"&state={token}&prompt=none" return { @@ -371,13 +370,13 @@ async def bridge_bind_delete(mx_id: str, code: str = None, state: str = None): existing: Optional[BridgeBind] = await get_or_none(BridgeBind, matrix_id=mx_id) if not existing: raise HTTPException(404, "Not found") - + if not (code and state) or state not in app.state.binds: token = secrets.token_urlsafe() app.state.binds[token] = mx_id url = discord.utils.oauth_url( - OAUTH_ID, - redirect_uri=BIND_REDIRECT_URI, + OAUTH_ID, + redirect_uri=BIND_REDIRECT_URI, scopes=("identify",) ) + f"&state={token}&prompt=none" return JSONResponse({"status": "pending", "url": url}) @@ -392,6 +391,7 @@ async def bridge_bind_delete(mx_id: str, code: str = None, state: str = None): await existing.delete() return JSONResponse({"status": "ok"}, 200) + @app.get("/bridge/bind/{mx_id}", dependencies=[Depends(is_authenticated)]) async def bridge_bind_fetch(mx_id: str): """Fetch the discord account associated with a matrix account."""