From 1cbf024f18afd4fadfde4ac8bd4f902a703a99d5 Mon Sep 17 00:00:00 2001 From: Zomatree <39768508+Zomatree@users.noreply.github.com> Date: Tue, 19 Oct 2021 18:09:33 +0100 Subject: [PATCH] remove file - the secret is invalid anyway --- a.py | 44 -------------------------------------------- 1 file changed, 44 deletions(-) delete mode 100755 a.py diff --git a/a.py b/a.py deleted file mode 100755 index 5cd9dfd..0000000 --- a/a.py +++ /dev/null @@ -1,44 +0,0 @@ -from aiohttp import web, web_request -import aiohttp - -API_ENDPOINT = 'https://discord.com/api/v8' -CLIENT_ID = '380423502810972162' -CLIENT_SECRET = 'pt1qgGOiWWhroqPM_NBqM_Nb1OSuySgU' -REDIRECT_URI = 'http://127.0.0.1:8080' - -async def exchange_code(code): - data = { - 'client_id': CLIENT_ID, - 'client_secret': CLIENT_SECRET, - 'grant_type': 'authorization_code', - 'code': code, - 'redirect_uri': REDIRECT_URI - } - headers = { - 'Content-Type': 'application/x-www-form-urlencoded' - } - async with aiohttp.ClientSession() as session: - r = await session.post(f'{API_ENDPOINT}/oauth2/token', data=data, headers=headers) - r.raise_for_status() - return await r.json() - -async def get_user(token): - headers = { - "Authorization": f"Bearer {token}" - } - - async with aiohttp.ClientSession() as session: - r = await session.get(f"{API_ENDPOINT}/users/@me") - r.raise_for_status() - return await r.json() - -async def hello(request: web_request.Request): - code = request.query["code"] - data = await exchange_code(code) - user = await get_user(data["access_token"]) - - return web.Response(text=user["email"]) - -app = web.Application() -app.add_routes([web.get('/', hello)]) -web.run_app(app)