總的來說,我對 FastAPI 和 OAuth2 很陌生。我剛剛完成了教程
我單擊授權并輸入我的憑據。(用戶名:johndoe,密碼:secret)

現在我可以訪問/users/me端點。

Notice how the header Authorization: Bearer johndoe was automagically included in my request.
Last notes:
- I've checked my cookies, session storage, and local storage and all are empty
- The authorization header disappears if I refresh the page or open a new tab
I suspect Swagger is doing something under the hood here, but I can't put my finger on it.
uj5u.com熱心網友回復:
如果您需要持久化令牌,您通常會使用 localStorage 或類似方法,但在 SwaggerUI 的特定情況下,身份驗證資訊保存在庫內部。
如果您啟用了持久性,SwaggerUI會將訪問令牌持久化到 localStorage:
export const persistAuthorizationIfNeeded = () => ( { authSelectors, getConfigs } ) => {
const configs = getConfigs()
if (configs.persistAuthorization)
{
const authorized = authSelectors.authorized()
localStorage.setItem("authorized", JSON.stringify(authorized.toJS()))
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/351503.html
