feat: jwt过期时间以s为单位

This commit is contained in:
martsforever
2025-08-22 17:11:26 +08:00
parent 44f35e7204
commit fc3909a08a
3 changed files with 10 additions and 10 deletions
+2 -2
View File
@@ -20,7 +20,7 @@ SERVER_DOMAIN = http://127.0.0.1 # 后端服务部署的
JWT_SECRET_KEY = a2d41c19c766490a2bea4be9902ea9f60e44ca3d9ef82e8b803f77a4f9deb247 # JWT秘钥
JWT_ALGORITHM = HS256 # JWT加密算法
JWT_ACCESS_TOKEN_EXPIRE_MINUTES = 30 # JWT访问令牌默认有效时间(分钟)
JWT_REFRESH_TOKEN_EXPIRE_MINUTES = 10080 # JWT刷新令牌默认有效时间(分钟)24*60*7 = 10080
JWT_ACCESS_TOKEN_EXPIRE_SECONDS = 1800 # JWT访问令牌默认有效时间(秒,1800s为30分钟)
JWT_REFRESH_TOKEN_EXPIRE_SECONDS = 604800 # JWT刷新令牌默认有效时间(描秒,604800s为7天)
JWT_GLOBAL_ENABLE = false # 是否开启全局JWT认证
JWT_WHITE_LIST = ["/token", "/login", "/refresh", "/registry", "/verify", "/async_delay"] # JWT认证白名单接口,不需要认证的接口
+2 -2
View File
@@ -28,8 +28,8 @@ class Settings(BaseSettings):
jwt_secret_key: str = Field(..., env="JWT_SECRET_KEY")
jwt_algorithm: str = Field(..., env="JWT_ALGORITHM")
jwt_access_token_expire_minutes: int = Field(..., env="JWT_ACCESS_TOKEN_EXPIRE_MINUTES")
jwt_refresh_token_expire_minutes: int = Field(..., env="JWT_REFRESH_TOKEN_EXPIRE_MINUTES")
jwt_access_token_expire_seconds: int = Field(..., env="JWT_ACCESS_TOKEN_EXPIRE_SECONDS")
jwt_refresh_token_expire_seconds: int = Field(..., env="JWT_REFRESH_TOKEN_EXPIRE_SECONDS")
jwt_global_enable: bool = Field(..., env="JWT_GLOBAL_ENABLE")
jwt_white_list: List[str] = Field(..., env="JWT_WHITE_LIST")
+6 -6
View File
@@ -141,16 +141,16 @@ def add_user_route(app: FastAPI):
access_token = CryptUtils.create_token(
username=user.username,
type="access",
expires_delta=timedelta(minutes=env.jwt_access_token_expire_minutes),
expires_delta=timedelta(seconds=env.jwt_access_token_expire_seconds),
)
access_expires = env.jwt_access_token_expire_minutes * 60 * 1000
access_expires = env.jwt_access_token_expire_seconds * 1000
refresh_token = CryptUtils.create_token(
username=user.username,
type="refresh",
expires_delta=timedelta(minutes=env.jwt_refresh_token_expire_minutes),
expires_delta=timedelta(minutes=env.jwt_refresh_token_expire_seconds),
)
refresh_expires = env.jwt_refresh_token_expire_minutes * 60 * 1000
refresh_expires = env.jwt_refresh_token_expire_seconds * 1000
return {
"result": user,
@@ -173,9 +173,9 @@ def add_user_route(app: FastAPI):
access_token = CryptUtils.create_token(
username=token_info.get("username"),
type="access",
expires_delta=timedelta(minutes=env.jwt_access_token_expire_minutes),
expires_delta=timedelta(minutes=env.jwt_access_token_expire_seconds),
)
access_expires = env.jwt_access_token_expire_minutes * 60 * 1000
access_expires = env.jwt_access_token_expire_seconds * 1000
return {
"access_token": access_token,
"access_expires": access_expires,