diff --git a/pixels/templates/api_token.html b/pixels/templates/api_token.html
index 976154f..ffc9b0f 100644
--- a/pixels/templates/api_token.html
+++ b/pixels/templates/api_token.html
@@ -23,11 +23,14 @@
-
API token:
+
Refresh token:
+
+
You're not done quite yet! You need to turn this into an access token before making requests to the API.
+
Refer to the documentation for how to do this.
diff --git a/pixels/utils/auth.py b/pixels/utils/auth.py
index e628b59..cf958a4 100644
--- a/pixels/utils/auth.py
+++ b/pixels/utils/auth.py
@@ -39,11 +39,12 @@ async def __call__(self, request: Request):
# Handle bad scenarios
+ if token_data["grant_type"] != "access_token":
+ raise HTTPException(status_code=403, detail=AuthState.WRONG_TOKEN.value)
+
expired = int(token_data["expiration"]) < datetime.now(timezone.utc).timestamp()
if user_state is None or user_state["key_salt"] != token_data["salt"] or expired:
raise HTTPException(status_code=403, detail=AuthState.INVALID_TOKEN.value)
- elif token_data["grant_type"] != "refresh_token":
- raise HTTPException(status_code=403, detail=AuthState.WRONG_TOKEN)
elif user_state["is_banned"]:
raise HTTPException(status_code=403, detail=AuthState.BANNED.value)
elif self.is_mod_endpoint and not user_state["is_mod"]:
@@ -78,7 +79,7 @@ async def reset_user_token(conn: Connection, user_id: str) -> str:
return jwt.encode(
{
"id": user_id,
- "grant_type": "authorization_code",
+ "grant_type": "refresh_token",
"salt": token_salt
},
Server.JWT_SECRET,
@@ -98,6 +99,9 @@ async def generate_access_token(conn: Connection, refresh_token: str) -> str:
except JWTError:
raise HTTPException(status_code=403, detail=AuthState.INVALID_TOKEN.value)
+ if token_data["grant_type"] != "refresh_token":
+ raise HTTPException(status_code=403, detail=AuthState.WRONG_TOKEN.value)
+
is_banned, key_salt = await conn.fetchrow(
"SELECT is_banned, key_salt FROM users WHERE user_id = $1", int(token_data["id"])
)
@@ -110,7 +114,7 @@ async def generate_access_token(conn: Connection, refresh_token: str) -> str:
return jwt.encode(
{
"id": token_data["id"],
- "grant_type": "refresh_token",
+ "grant_type": "access_token",
"expiration": expiration.timestamp(),
"salt": key_salt
},