Oauth Anthentication #48

Merged
Xefir merged 13 commits from v2 into master 2022-09-12 18:47:37 +00:00
Showing only changes of commit 6775e09c7a - Show all commits

View File

@ -3,7 +3,7 @@ import logging
from datetime import datetime, timedelta from datetime import datetime, timedelta
from functools import wraps from functools import wraps
from os import environ, path from os import environ, path
from typing import Optional from typing import Dict, List, Optional
from disnake import Client, Guild from disnake import Client, Guild
from dotenv import load_dotenv from dotenv import load_dotenv
@ -78,7 +78,9 @@ def token_updater(token: str):
session["oauth2_token"] = token session["oauth2_token"] = token
def make_session(token=None, state=None, scope=None) -> OAuth2Session: def make_session(
token: Optional[Dict[str, str]], state=Optional[str], scope=Optional[List[str]]
) -> OAuth2Session:
return OAuth2Session( return OAuth2Session(
client_id=OAUTH2_CLIENT_ID, client_id=OAUTH2_CLIENT_ID,
token=token, token=token,
@ -176,8 +178,7 @@ async def callback():
@app.route("/guilds") @app.route("/guilds")
@login_required @login_required
async def guilds(): async def guilds():
guild_id = request.args.get("guild") guild = get_guild_by_id(request.args.get("guild"))
guild = get_guild_by_id(guild_id)
if guild: if guild:
return redirect( return redirect(
@ -212,9 +213,7 @@ async def subscribe(guild_id: str):
if not any(str(guild.id) == user_guild["id"] for user_guild in user_guilds): if not any(str(guild.id) == user_guild["id"] for user_guild in user_guilds):
return redirect(url_for(".login")) return redirect(url_for(".login"))
user = discord.get(f"{API_BASE_URL}/users/@me").json() return await render_template("subscribe.html.j2", guild=guild)
return await render_template("subscribe.html.j2", user=user, guild=guild)
@app.route("/<guild_id>.ics") @app.route("/<guild_id>.ics")