diff options
author | 2021-03-09 08:48:58 +0200 | |
---|---|---|
committer | 2021-03-09 08:48:58 +0200 | |
commit | 0ec4a370d476f3f8b7453c887b0b02fe83aced9c (patch) | |
tree | e7fb0e7a71369affd79222445a35438815ad4cd3 /backend/discord.py | |
parent | Add missing "is" to error message (diff) | |
parent | Fixes Production URL Constant (diff) |
Merge branch 'main' into ks123/role-assigning
Diffstat (limited to 'backend/discord.py')
-rw-r--r-- | backend/discord.py | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/backend/discord.py b/backend/discord.py index 1dc8ed7..e5c7f8f 100644 --- a/backend/discord.py +++ b/backend/discord.py @@ -2,20 +2,25 @@ import httpx from backend.constants import ( - DISCORD_API_BASE_URL, OAUTH2_CLIENT_ID, OAUTH2_CLIENT_SECRET, OAUTH2_REDIRECT_URI + DISCORD_API_BASE_URL, OAUTH2_CLIENT_ID, OAUTH2_CLIENT_SECRET ) -async def fetch_bearer_token(access_code: str) -> dict: +async def fetch_bearer_token(code: str, redirect: str, *, refresh: bool) -> dict: async with httpx.AsyncClient() as client: data = { "client_id": OAUTH2_CLIENT_ID, "client_secret": OAUTH2_CLIENT_SECRET, - "grant_type": "authorization_code", - "code": access_code, - "redirect_uri": OAUTH2_REDIRECT_URI + "redirect_uri": f"{redirect}/callback" } + if refresh: + data["grant_type"] = "refresh_token" + data["refresh_token"] = code + else: + data["grant_type"] = "authorization_code" + data["code"] = code + r = await client.post(f"{DISCORD_API_BASE_URL}/oauth2/token", headers={ "Content-Type": "application/x-www-form-urlencoded" }, data=data) |