Skip to content

Commit

Permalink
fix(security): handle errors and prevent unnecessary token refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
InfinityPacer committed Oct 9, 2024
1 parent 871f8d3 commit 55403cd
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions app/core/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,10 @@ def __set_or_refresh_resource_token_cookie(request: Request, response: Response,
# 如果剩余时间少于 2 分钟,刷新令牌
if remaining_time < timedelta(minutes=2):
raise jwt.ExpiredSignatureError
except jwt.ExpiredSignatureError:
# 如果令牌过期或即将过期,刷新令牌
pass
except jwt.PyJWTError:
logger.debug(f"Token error occurred. refreshing token")
except Exception as e:
logger.debug(f"Unexpected error occurred while decoding token: {e}")
else:
# 如果令牌有效且没有即将过期,则不需要刷新
return
Expand Down

0 comments on commit 55403cd

Please sign in to comment.