INNER CODE UNIT · Python
get_valid_token
datawhalechina/wow-fullstack · tutorial/FastAPI/第6章-FastAPI MCP/main.py:147
def get_valid_token():
current_time = int(time.time())
# 检查缓存中的令牌是否有效
if token_cache["token"] and token_cache["expires_at"] > current_time:
return token_cache["token"]
# 生成新令牌
return generate_jwt()
@app.post("/generate-jwt", operation_id="generate_jwt", tags=["JWT"])
async def create_jwt(
request: JWTRequest = JWTRequest()
):
"""
生成JWT令牌的API端点
参数: