mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-13 01:00:12 +00:00
Update api_main.py
Removing API-side OAuth flow to accept a Discord token from the request
This commit is contained in:
parent
d0c9a24521
commit
9d3c417f52
1 changed files with 2 additions and 17 deletions
|
|
@ -186,24 +186,9 @@ class Handlers:
|
||||||
return web.json_response(await switch.to_json(hid_getter))
|
return web.json_response(await switch.to_json(hid_getter))
|
||||||
|
|
||||||
async def discord_oauth(request):
|
async def discord_oauth(request):
|
||||||
code = await request.text()
|
access_token = await request.text()
|
||||||
async with ClientSession() as sess:
|
async with ClientSession() as sess:
|
||||||
data = {
|
|
||||||
'client_id': os.environ["CLIENT_ID"],
|
|
||||||
'client_secret': os.environ["CLIENT_SECRET"],
|
|
||||||
'grant_type': 'authorization_code',
|
|
||||||
'code': code,
|
|
||||||
'redirect_uri': os.environ["REDIRECT_URI"],
|
|
||||||
'scope': 'identify'
|
|
||||||
}
|
|
||||||
headers = {
|
|
||||||
'Content-Type': 'application/x-www-form-urlencoded'
|
|
||||||
}
|
|
||||||
res = await sess.post("https://discordapp.com/api/v6/oauth2/token", data=data, headers=headers)
|
|
||||||
if res.status != 200:
|
|
||||||
raise web.HTTPBadRequest()
|
|
||||||
|
|
||||||
access_token = (await res.json())["access_token"]
|
|
||||||
res = await sess.get("https://discordapp.com/api/v6/users/@me", headers={"Authorization": "Bearer " + access_token})
|
res = await sess.get("https://discordapp.com/api/v6/users/@me", headers={"Authorization": "Bearer " + access_token})
|
||||||
user_id = int((await res.json())["id"])
|
user_id = int((await res.json())["id"])
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue