Browse Source

feat: source统一小写比较

zhangwl 2 months ago
parent
commit
9f0c457006
1 changed files with 3 additions and 3 deletions
  1. 3 3
      app/routers/users.py

+ 3 - 3
app/routers/users.py

@@ -406,7 +406,7 @@ async def login_with_third_party(
         HTTPException: 如果token无效或source不是"app"
         HTTPException: 如果token无效或source不是"app"
     """
     """
     # 验证source是否为"app"
     # 验证source是否为"app"
-    if login_data.source != "app":
+    if login_data.source.lower() != "app":
         raise HTTPException(
         raise HTTPException(
             status_code=status.HTTP_400_BAD_REQUEST,
             status_code=status.HTTP_400_BAD_REQUEST,
             detail="Invalid source"
             detail="Invalid source"
@@ -423,12 +423,12 @@ async def login_with_third_party(
 
 
     # 创建访问令牌和刷新令牌
     # 创建访问令牌和刷新令牌
     access_token = create_access_token(
     access_token = create_access_token(
-        data={"sub": user_info["nickName"], "userId": user_info["userId"], "source": login_data.source},
+        data={"sub": user_info["nickName"], "userId": user_info["userId"], "source": login_data.source.lower()},
         expires_delta=timedelta(minutes=config.ACCESS_TOKEN_EXPIRE_MINUTES),
         expires_delta=timedelta(minutes=config.ACCESS_TOKEN_EXPIRE_MINUTES),
         token_type="access"
         token_type="access"
     )
     )
     refresh_token = create_access_token(
     refresh_token = create_access_token(
-        data={"sub": user_info["nickName"], "userId": user_info["userId"], "source": login_data.source},
+        data={"sub": user_info["nickName"], "userId": user_info["userId"], "source": login_data.source.lower()},
         expires_delta=timedelta(days=7),
         expires_delta=timedelta(days=7),
         token_type="refresh"
         token_type="refresh"
     )
     )