I'm pretty new to FastAPI and OAuth2 in general. I just worked through the tutorial
I click Authorize and enter my credentials. (username: johndoe
, password: secret
)
And now I can access the /users/me
endpoint.
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.
CodePudding user response:
If you need persistence for the token you'd usually use localStorage or similar, but in SwaggerUIs specific case, the authentication information is kept internally in the library.
If you have enabled persistence SwaggerUI will persistent the access token to localStorage:
export const persistAuthorizationIfNeeded = () => ( { authSelectors, getConfigs } ) => {
const configs = getConfigs()
if (configs.persistAuthorization)
{
const authorized = authSelectors.authorized()
localStorage.setItem("authorized", JSON.stringify(authorized.toJS()))
}
}