aboutsummaryrefslogtreecommitdiffstats
path: root/backend/discord.py
diff options
context:
space:
mode:
authorGravatar Joe Banks <[email protected]>2021-03-06 19:54:33 +0000
committerGravatar GitHub <[email protected]>2021-03-06 19:54:33 +0000
commit0f363c26271594de42ee05bb59a99e99c6e12de1 (patch)
tree2e409cac18da2f976b5593065a185cec01e90c85 /backend/discord.py
parentMerge pull request #62 from python-discord/dependabot/pip/uvicorn-0.13.4 (diff)
parentMerge branch 'main' into token-expiry (diff)
Merge pull request #58 from python-discord/token-expiry
Diffstat (limited to 'backend/discord.py')
-rw-r--r--backend/discord.py15
1 files changed, 10 insertions, 5 deletions
diff --git a/backend/discord.py b/backend/discord.py
index d6310b7..8cb602c 100644
--- a/backend/discord.py
+++ b/backend/discord.py
@@ -2,22 +2,27 @@
import httpx
from backend.constants import (
- OAUTH2_CLIENT_ID, OAUTH2_CLIENT_SECRET, OAUTH2_REDIRECT_URI
+ OAUTH2_CLIENT_ID, OAUTH2_CLIENT_SECRET
)
API_BASE_URL = "https://discord.com/api/v8"
-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"{API_BASE_URL}/oauth2/token", headers={
"Content-Type": "application/x-www-form-urlencoded"
}, data=data)