|
5 | 5 | from logging import getLogger
|
6 | 6 |
|
7 | 7 | import jwt
|
8 |
| -from fastapi import APIRouter, Header, Response, HTTPException, Depends |
| 8 | +from fastapi import APIRouter, Depends, Header, HTTPException, Response |
9 | 9 | from passlib.hash import bcrypt
|
10 | 10 | from pydantic import BaseModel
|
11 | 11 | from tortoise.transactions import atomic
|
12 | 12 |
|
13 |
| -from pwncore.models import Team, User |
14 | 13 | from pwncore.config import config
|
| 14 | +from pwncore.models import Team, User |
15 | 15 |
|
16 | 16 | # Metadata at the top for instant accessibility
|
17 | 17 | metadata = {
|
@@ -117,8 +117,14 @@ def get_jwt(*, authorization: t.Annotated[str, Header()]) -> JwtInfo:
|
117 | 117 | decoded_token: JwtInfo = jwt.decode(
|
118 | 118 | token, config.jwt_secret, algorithms=["HS256"]
|
119 | 119 | )
|
120 |
| - except Exception as err: # Will filter for invalid signature/expired tokens |
121 |
| - logger.warning("Invalid login", exc_info=err) |
| 120 | + except ( |
| 121 | + jwt.exceptions.DecodeError |
| 122 | + ) as err: # Will filter for invalid signature/expired tokens |
| 123 | + logger.warning("Decode error", exc_info=err) |
| 124 | + raise HTTPException(status_code=401) |
| 125 | + |
| 126 | + except jwt.exceptions.InvalidTokenError as err: |
| 127 | + logger.warning("Invalid token", exc_info=err) |
122 | 128 | raise HTTPException(status_code=401)
|
123 | 129 | return decoded_token
|
124 | 130 |
|
|
0 commit comments