【发布时间】:2021-01-28 08:45:41
【问题描述】:
我在 FastAPI web site 上关注有关安全性的教程
以具有以下端点结束:
@app.post("/token", response_model= Token)
async def login(form_data: OAuth2PasswordRequestForm = Depends()):
user = authenticate_user(fake_users_db, form_data.username, form_data.password)
if not user:
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail="Incorrect username or password",
headers={"WWW-Authenticate": "Bearer"},
)
access_token_expires = timedelta(minutes=ACCESS_TOKEN_EXPIRE_MINUTES)
access_token = create_access_token(
data={"sub": user.username}, expires_delta=access_token_expires
)
return {"access_token": access_token, "token_type": "bearer"}
导致以下招摇:
我的问题: 有没有一种简单的方法来屏蔽密码字段?所以我没有在纯文本中看到它? 就像我们可以使用授权按钮一样。
【问题讨论】:
-
另外,您可以点击右上角的“授权”按钮,而不是直接使用 /login 路由,这样会屏蔽密码表单输入。
标签: python-3.x openapi fastapi